@@ -14,7 +14,6 @@ import (
1414 "github.com/ory/viper"
1515 "github.com/spf13/cobra"
1616 "k8s.io/apimachinery/pkg/api/resource"
17- "k8s.io/client-go/tools/clientcmd"
1817 "knative.dev/client/pkg/util"
1918
2019 "knative.dev/func/pkg/builders"
@@ -289,57 +288,6 @@ Try this:
289288For more options, run 'func deploy --help'` , fn .ErrClusterNotAccessible )
290289}
291290
292- // validateClusterConnection checks if the Kubernetes cluster is accessible before starting build
293- func validateClusterConnection () error {
294- // Try to get cluster configuration
295- restConfig , err := k8s .GetClientConfig ().ClientConfig ()
296- if err != nil {
297- kubeconfigPath := os .Getenv ("KUBECONFIG" )
298-
299- // Check if this is an empty/missing config error
300- if clientcmd .IsEmptyConfig (err ) {
301- // If KUBECONFIG is explicitly set, check if the file exists
302- if kubeconfigPath != "" {
303- if _ , statErr := os .Stat (kubeconfigPath ); os .IsNotExist (statErr ) {
304- // File doesn't exist - return invalid kubeconfig error for real usage
305- // but skip for test paths (tests may have stale KUBECONFIG paths)
306- if ! strings .Contains (kubeconfigPath , "/testdata/" ) &&
307- ! strings .Contains (kubeconfigPath , "\\ testdata\\ " ) {
308- return fmt .Errorf ("%w: %v" , fn .ErrInvalidKubeconfig , err )
309- }
310- // Test path - skip validation
311- return nil
312- }
313- }
314- return fmt .Errorf ("%w: %v" , fn .ErrClusterNotAccessible , err )
315- }
316- return fmt .Errorf ("%w: %v" , fn .ErrClusterNotAccessible , err )
317- }
318-
319- // Skip connectivity check for non-production clusters (example, test, localhost)
320- host := restConfig .Host
321- if strings .Contains (host , ".example.com" ) ||
322- strings .Contains (host , "example.com:" ) ||
323- strings .Contains (host , "localhost" ) ||
324- strings .Contains (host , "127.0.0.1" ) {
325- return nil
326- }
327-
328- // Create Kubernetes client to test connectivity
329- client , err := k8s .NewKubernetesClientset ()
330- if err != nil {
331- return fmt .Errorf ("%w: %v" , fn .ErrClusterNotAccessible , err )
332- }
333-
334- // Verify cluster is actually reachable with an API call
335- _ , err = client .Discovery ().ServerVersion ()
336- if err != nil {
337- return fmt .Errorf ("%w: %v" , fn .ErrClusterNotAccessible , err )
338- }
339-
340- return nil
341- }
342-
343291func runDeploy (cmd * cobra.Command , newClient ClientFactory ) (err error ) {
344292 var (
345293 cfg deployConfig
@@ -419,17 +367,6 @@ For more options, run 'func deploy --help'`, err)
419367 }
420368 cmd .SetContext (cfg .WithValues (cmd .Context ())) // Some optional settings are passed via context
421369
422- // Validate cluster connection before building
423- if err = validateClusterConnection (); err != nil {
424- if errors .Is (err , fn .ErrInvalidKubeconfig ) {
425- return wrapInvalidKubeconfigError (err )
426- }
427- if errors .Is (err , fn .ErrClusterNotAccessible ) {
428- return wrapClusterNotAccessibleError (err )
429- }
430- return err
431- }
432-
433370 changingNamespace := func (f fn.Function ) bool {
434371 // We're changing namespace if:
435372 return f .Deploy .Namespace != "" && // it's already deployed
@@ -469,6 +406,12 @@ For more options, run 'func deploy --help'`, err)
469406 // Returned is the function with fields like Registry, f.Deploy.Image &
470407 // f.Deploy.Namespace populated.
471408 if url , f , err = client .RunPipeline (cmd .Context (), f ); err != nil {
409+ if errors .Is (err , fn .ErrInvalidKubeconfig ) {
410+ return wrapInvalidKubeconfigError (err )
411+ }
412+ if errors .Is (err , fn .ErrClusterNotAccessible ) {
413+ return wrapClusterNotAccessibleError (err )
414+ }
472415 return
473416 }
474417 fmt .Fprintf (cmd .OutOrStdout (), "Function Deployed at %v\n " , url )
@@ -520,6 +463,12 @@ For more options, run 'func deploy --help'`, err)
520463 }
521464 }
522465 if f , err = client .Deploy (cmd .Context (), f , fn .WithDeploySkipBuildCheck (cfg .Build == "false" )); err != nil {
466+ if errors .Is (err , fn .ErrInvalidKubeconfig ) {
467+ return wrapInvalidKubeconfigError (err )
468+ }
469+ if errors .Is (err , fn .ErrClusterNotAccessible ) {
470+ return wrapClusterNotAccessibleError (err )
471+ }
523472 return
524473 }
525474 }
0 commit comments