Washington (CNN) On Friday, June 21, acting Homeland Security Secretary Kevin McAleenan went to the White House prepared to resign.

Days earlier, President Donald Trump had issued a vague threat to deport "millions" of undocumented immigrants, providing few details of the effort and surprising officials within his own administration. McAleenan was concerned that the operation was half-baked and too far-reaching in scope. And he felt undermined by subordinate immigration hardliners who had a direct line to the President over the issue that Trump cares most about, two sources familiar with the matter said.

Then-acting Director of Immigration and Customs Enforcement Mark Morgan had begun hyping an upcoming operation targeting undocumented migrant families for deportation and was speaking directly with the President about it, according to a source familiar with the situation.

Arriving at the White House, McAleenan met with the acting White House chief of staff Mick Mulvaney and his deputy Emma Doyle, to make his case. The raids, he said, would anger Democrats and jeopardize the administration's request for emergency funding for the border; they should be conducted in phases rather than all at once; and he argued the department needed more time to build out the proper messaging, said a former senior administration official.

On June 22, Trump suspended the operation, citing objections from Democratic lawmakers. But it's not clear Democratic objections drove his decision and sources said Trump's decision to postpone the operation allayed McAleenan's concerns that his advice as the DHS chief was not being heeded. And, days later, Congress passed the $4.5 billion emergency border funding bill that McAleenan thought the ICE raids could undermine.

Immigration hardliners accused McAleenan, without direct evidence, of leaking details of the ICE operation, charges he has denied. The operation targeting 2,000 families ordered removed by an immigration judge eventually took place a month later, but fell short of its goal -- resulting in the arrest of 35 migrants

The episode put into view the tensions within the Department of Homeland Security and the rocky relationship between McAleenan and the White House. McAleenan, who has been increasingly surrounded by Trump loyalists and immigration hardliners, has at times been frustrated that some officials go around him, as he has grappled for control of the department, multiple administration officials tell CNN.

McAleenan took over in April after Secretary Kirstjen Nielsen was pushed out of her role at the urging of White House senior adviser and immigration hardliner Stephen Miller. McAleenan, who was commissioner of Customs and Border Protection, had the backing of the President's son-in-law and adviser Jared Kushner.

But while Trump elevated McAleenan, he still sees the acting secretary -- a career official who served under Presidents George W. Bush and Barack Obama -- as having an allegiance to the previous administration.

In a meeting with congressional Democrats about the government shutdown earlier this year, the President referred to McAleenan, then at CBP, as an "Obama guy," Axios first reported in April.

McAleenan served under the former president, eventually rising through the ranks to the highest-ranking career position at Customs and Border Protection.

The President often still makes comments that McAleenan should go talk to Democrats since he knows how to deal with them, according to a source.

The relationship, however, runs hot and cold based on the numbers of migrants crossing the border and headlines the President doesn't like, sources tell CNN.

JUST WATCHED Girl pleads with official during ICE arrests Replay More Videos ... MUST WATCH Girl pleads with official during ICE arrests 00:40

Deputy press secretary Hogan Gidley praised McAleenan in a statement after this story published.

"In just a short time at the helm of DHS, Acting Secretary McAleenan has already substantially reduced illegal border-crossings, greatly expanded regional burden sharing, advanced vitally-important regulations, and significantly boosted the rapid removal and return of illegal aliens -- despite relentless obstruction from activist far-left judges and belligerently open-borders Democrat Lawmakers," Gidley said in a statement.

Four months into the role, McAleenan has had to navigate a migration crisis at the southern border and a White House that has shunned the traditional policy processes, all while leading the third largest federal department in the wake of a purge that left DHS and many of its component agencies without permanent leadership.

"It's arguably the most politically-charged job in government right now," said a senior DHS official about the acting secretary role.

In recent months, the three main immigration components in DHS have had a change in leadership -- Customs and Border Protection, Immigration and Customs Enforcement, and US Citizenship and Immigration Services. The President's decision to swap out leadership appeared to be motivated by his desire to go in a "tougher direction," as he once said, amid a swell of migrants arriving at the US-Mexico border.

Trump's personnel choices have, on occasion, have had ideological conflicts with McAleenan. In addition to Morgan, Ken Cuccinelli, an immigration hardliner and former Virginia state attorney general, took over as acting head of US Citizenship and Immigration Services in June.

The White House, led by Mulvaney, previously looked into replacing McAleenan with Cuccinelli, who's been a public face on television on the President's policies, as acting secretary. A senior administration official said that option is no longer being considered.

A White House official told CNN that the "President expects the acting secretary to continue his work" on "many additional policy changes," regulations, and foreign cooperative agreements.

However, McAleenan isn't expected to be offered the permanent secretary position, according to sources.

"There's still some apprehension. Everyone is waiting for the other shoe to drop," said a DHS official about concerns over more leadership changes to come.

Trump told Fox News in June that McAleenan was "doing a nice job," when asked about whether he will nominate him for the permanent secretary role.

"McAleenan, he is doing a very nice job. We're going to see. I've got to get used to him because it's a very important thing to me, the border. We need strong people at the border. And if people aren't strong, they're not going to do a good job."

Despite the uncertainty that an acting role brings, multiple current and former DHS officials have praised McAleenan's depth of knowledge, operational experience and leadership.

"I think it's really hard being acting," said a former official. "He is taking, if you will, taking the bull by the horns and spent his time doing the job."

JUST WATCHED AOC confronts DHS chief over border agent Facebook group Replay More Videos ... MUST WATCH AOC confronts DHS chief over border agent Facebook group 02:37

Trump focuses on numbers

US-Mexico border apprehension numbers are particularly important to Trump, who reviews the numbers at the beginning of each month and views them as a barometer of the situation along the southern border, according to administration officials.

Under his tenure as acting secretary, border apprehensions continued to soar to their highest level in a decade -- more than 130,000 -- before falling 20% in June and 24% in July , a drop that McAleenan attributes in part to a recent agreement with Mexico on immigration enforcement.

The numbers continue to go down for now, according to a source familiar with the trajectory, though they still exceed levels a year ago.

The White House has taken a retaliatory approach to immigration, rolling out policies that seek to discourage those who journey to the US-Mexico border. In March, the US announced it was cutting off aid to El Salvador, Guatemala and Honduras, which the President accused of having "set up" migrant caravans for entry into the US.

McAleenan, who has been a proponent of regional investment in Central America, was not supportive of the move to freeze aid to the Northern Triangle, according to a former administration official.

During a visit to Guatemala at the end of May, McAleenan told CNN Trump was looking for investments that have a return on US interests, including the ability to address the causes of migration. The "key measure" of success is whether aid leads to a halt of migration to the US, he said.

"I think there's some very valid aid efforts that are ongoing but we got to assess them all carefully and make sure we're making the right investments," he said.

The architect at the core of the administration's immigration policies is White House senior adviser Miller, who had a hand in the purge within DHS earlier this year.

"I don't think anybody that works in the [immigration enforcement] space is eager to participate with him," said a former administration official, referring to Miller.

But McAleenan "understands what Stephen's role is," the official added. Still, the two have clashed over Miller's attempts to make personnel changes within DHS, like placing Morgan into the role of acting CBP chief, according to a source familiar with the disagreement.

But McAleenan has forged a relationship with Kushner, the President's son-in-law, according to current and former administration officials, who released a proposal to reform the country's immigration system earlier this year.

During White House meetings, "you could tell" they had a "close working relationship," said a former official.

A department roiled by turnover

Since assuming the acting secretary role, McAleenan has focused almost all of his public attention on immigration issues, while running a department that is also responsible for terrorism prevention, election security and natural disaster response. The acting secretary recently canceled a trip to London to travel to Guatemala to work on a new asylum deal that would return most migrants to Guatemala if they did not try to seek asylum there before journeying to the US.

At the end of July, Trump, standing behind McAleenan announced the asylum deal in the Oval Office.

The tension within the department's leadership ranks has become evident over time amid conflicting immigration views.

"The clash of those two views has caused a dysfunctional relationship within the leadership" at the department, said the source, referring to diverging views on immigration enforcement. "How do you repair the working relationships between the White House, and the [DHS] components? That seems ambitious, 'they are pretty frayed.'"

Morgan, who clashed with McAleenan over the raids, has since moved to Customs and Border Protection as acting commissioner, replacing John Sanders.

Sanders left the administration in part over concerns about the administration's rhetoric on ICE deportations, after the White House chose Morgan to serve at the acting commissioner, according to a source familiar with the personnel change.

McAleenan fought to keep Sanders at CBP, according to the source. With his departure McAleenan lost an ally at DHS.

"We've been surprised by the twists and turns in personnel," said a senior DHS official, who added that leadership appears to be in a "decent place now."