Just visited Gibraltar today and "The Rock", and I am curious if Gibraltar ever was threatened by any sort of invasion by the Axis forces? Or maybe even Spain at some point posed a large threat to Gibraltar?
Yes. The Germans came up with an assault plan called Operation Felix.
It never got past the basic planning stage though. Hitler never could convince Franco that siding with the Germans would put the Spanish on the right side of the war. Apparently a wise choice on the part of Franco. As Felix required Spain to allow German troops passage to Gibraltar, the whole thing remained dead in water.
I can't answer the main question, but I was immediately reminded of a bit of interesting context that may be helpful. While Eisenhower, the former Supreme Allied Commander in Europe, was the US President, many isolationist critics, including former President Herbert Hoover, suggested that America cease its activities abroad, bring its troops home and focus on becoming a "Gibraltar of Freedom." Eisenhower, ever the military strategist, was appalled by this metaphor, given that modern advancements in military technology Gibraltar was hardly the stronghold it has been 150 years earlier. As he said in response, "Today, Gibraltar is one of the weakest military spots in the world. It could be reduced to nothing by a few modern guns posted in the hills and concentrating their fire on it."
If Eisenhower was to have been tasked with taking Gibraltar, this should give us some idea of what that would have looked like, at least strategically.
This exchange is taken from Jean Edward Smith's Eisenhower: In War and Peace pg 511.