@@ -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"
@@ -290,57 +289,6 @@ Try this:
290289For more options, run 'func deploy --help'` , fn .ErrClusterNotAccessible )
291290}
292291
293- // validateClusterConnection checks if the Kubernetes cluster is accessible before starting build
294- func validateClusterConnection () error {
295- // Try to get cluster configuration
296- restConfig , err := k8s .GetClientConfig ().ClientConfig ()
297- if err != nil {
298- kubeconfigPath := os .Getenv ("KUBECONFIG" )
299-
300- // Check if this is an empty/missing config error
301- if clientcmd .IsEmptyConfig (err ) {
302- // If KUBECONFIG is explicitly set, check if the file exists
303- if kubeconfigPath != "" {
304- if _ , statErr := os .Stat (kubeconfigPath ); os .IsNotExist (statErr ) {
305- // File doesn't exist - return invalid kubeconfig error for real usage
306- // but skip for test paths (tests may have stale KUBECONFIG paths)
307- if ! strings .Contains (kubeconfigPath , "/testdata/" ) &&
308- ! strings .Contains (kubeconfigPath , "\\ testdata\\ " ) {
309- return fmt .Errorf ("%w: %v" , fn .ErrInvalidKubeconfig , err )
310- }
311- // Test path - skip validation
312- return nil
313- }
314- }
315- return fmt .Errorf ("%w: %v" , fn .ErrClusterNotAccessible , err )
316- }
317- return fmt .Errorf ("%w: %v" , fn .ErrClusterNotAccessible , err )
318- }
319-
320- // Skip connectivity check for non-production clusters (example, test, localhost)
321- host := restConfig .Host
322- if strings .Contains (host , ".example.com" ) ||
323- strings .Contains (host , "example.com:" ) ||
324- strings .Contains (host , "localhost" ) ||
325- strings .Contains (host , "127.0.0.1" ) {
326- return nil
327- }
328-
329- // Create Kubernetes client to test connectivity
330- client , err := k8s .NewKubernetesClientset ()
331- if err != nil {
332- return fmt .Errorf ("%w: %v" , fn .ErrClusterNotAccessible , err )
333- }
334-
335- // Verify cluster is actually reachable with an API call
336- _ , err = client .Discovery ().ServerVersion ()
337- if err != nil {
338- return fmt .Errorf ("%w: %v" , fn .ErrClusterNotAccessible , err )
339- }
340-
341- return nil
342- }
343-
344292func runDeploy (cmd * cobra.Command , newClient ClientFactory ) (err error ) {
345293 var (
346294 cfg deployConfig
@@ -436,17 +384,6 @@ For more options, run 'func deploy --help'`, err)
436384 }
437385 cmd .SetContext (cfg .WithValues (cmd .Context ())) // Some optional settings are passed via context
438386
439- // Validate cluster connection before building
440- if err = validateClusterConnection (); err != nil {
441- if errors .Is (err , fn .ErrInvalidKubeconfig ) {
442- return wrapInvalidKubeconfigError (err )
443- }
444- if errors .Is (err , fn .ErrClusterNotAccessible ) {
445- return wrapClusterNotAccessibleError (err )
446- }
447- return err
448- }
449-
450387 changingNamespace := func (f fn.Function ) bool {
451388 // We're changing namespace if:
452389 return f .Deploy .Namespace != "" && // it's already deployed
@@ -486,6 +423,12 @@ For more options, run 'func deploy --help'`, err)
486423 // Returned is the function with fields like Registry, f.Deploy.Image &
487424 // f.Deploy.Namespace populated.
488425 if url , f , err = client .RunPipeline (cmd .Context (), f ); err != nil {
426+ if errors .Is (err , fn .ErrInvalidKubeconfig ) {
427+ return wrapInvalidKubeconfigError (err )
428+ }
429+ if errors .Is (err , fn .ErrClusterNotAccessible ) {
430+ return wrapClusterNotAccessibleError (err )
431+ }
489432 return
490433 }
491434 fmt .Fprintf (cmd .OutOrStdout (), "Function Deployed at %v\n " , url )
@@ -537,6 +480,12 @@ For more options, run 'func deploy --help'`, err)
537480 }
538481 }
539482 if f , err = client .Deploy (cmd .Context (), f , fn .WithDeploySkipBuildCheck (cfg .Build == "false" )); err != nil {
483+ if errors .Is (err , fn .ErrInvalidKubeconfig ) {
484+ return wrapInvalidKubeconfigError (err )
485+ }
486+ if errors .Is (err , fn .ErrClusterNotAccessible ) {
487+ return wrapClusterNotAccessibleError (err )
488+ }
540489 return
541490 }
542491 }
0 commit comments