github.com/jenkins-x/jx/v2@v2.1.155/pkg/cmd/step/verify/step_verify_install.go (about) 1 package verify 2 3 import ( 4 "time" 5 6 "github.com/jenkins-x/jx/v2/pkg/cmd/opts/step" 7 8 "github.com/jenkins-x/jx-logging/pkg/log" 9 "github.com/jenkins-x/jx/v2/pkg/cloud" 10 "github.com/jenkins-x/jx/v2/pkg/cmd/helper" 11 "github.com/jenkins-x/jx/v2/pkg/cmd/opts" 12 "github.com/jenkins-x/jx/v2/pkg/config" 13 "github.com/jenkins-x/jx/v2/pkg/kube" 14 "github.com/jenkins-x/jx/v2/pkg/util" 15 "github.com/pkg/errors" 16 "github.com/spf13/cobra" 17 ) 18 19 // StepVerifyInstallOptions contains the command line flags 20 type StepVerifyInstallOptions struct { 21 StepVerifyOptions 22 Debug bool 23 Dir string 24 Namespace string 25 PodWaitDuration time.Duration 26 } 27 28 // NewCmdStepVerifyInstall creates the `jx step verify pod` command 29 func NewCmdStepVerifyInstall(commonOpts *opts.CommonOptions) *cobra.Command { 30 31 options := &StepVerifyInstallOptions{ 32 StepVerifyOptions: StepVerifyOptions{ 33 StepOptions: step.StepOptions{ 34 CommonOptions: commonOpts, 35 }, 36 }, 37 } 38 39 cmd := &cobra.Command{ 40 Use: "install", 41 Short: "Verifies that an installation is setup correctly", 42 Run: func(cmd *cobra.Command, args []string) { 43 options.Cmd = cmd 44 options.Args = args 45 err := options.Run() 46 helper.CheckErr(err) 47 }, 48 } 49 cmd.Flags().BoolVarP(&options.Debug, "debug", "", false, "Output logs of any failed pod") 50 cmd.Flags().StringVarP(&options.Dir, "dir", "d", ".", "the directory to look for the install requirements file") 51 cmd.Flags().StringVarP(&options.Namespace, "namespace", "", "", "the namespace that Jenkins X will be booted into. If not specified it defaults to $DEPLOY_NAMESPACE") 52 cmd.Flags().DurationVarP(&options.PodWaitDuration, "pod-wait-time", "w", time.Second, "The default wait time to wait for the pods to be ready") 53 return cmd 54 } 55 56 // Run implements this command 57 func (o *StepVerifyInstallOptions) Run() error { 58 ns, err := o.GetDeployNamespace(o.Namespace) 59 if err != nil { 60 return err 61 } 62 o.SetDevNamespace(ns) 63 64 log.Logger().Infof("verifying the Jenkins X installation in namespace %s\n", util.ColorInfo(ns)) 65 66 po := &StepVerifyPodReadyOptions{} 67 po.StepOptions = o.StepOptions 68 po.Debug = o.Debug 69 po.WaitDuration = o.PodWaitDuration 70 po.ExcludeBuildPods = true 71 72 log.Logger().Info("verifying pods\n") 73 err = po.Run() 74 if err != nil { 75 return err 76 } 77 78 gto := &StepVerifyGitOptions{} 79 gto.StepOptions = o.StepOptions 80 err = gto.Run() 81 if err != nil { 82 return err 83 } 84 85 requirements, _, err := config.LoadRequirementsConfig(o.Dir, config.DefaultFailOnValidationError) 86 if err != nil { 87 return err 88 } 89 kubeClient, err := o.KubeClient() 90 if err != nil { 91 return err 92 } 93 installValues, err := kube.ReadInstallValues(kubeClient, ns) 94 if err != nil { 95 return errors.Wrapf(err, "failed to read install values from namespace %s", ns) 96 } 97 provider := installValues[kube.KubeProvider] 98 if provider == "" { 99 log.Logger().Warnf("no %s in the ConfigMap %s. Has values %#v\n", kube.KubeProvider, kube.ConfigMapNameJXInstallConfig, installValues) 100 provider = requirements.Cluster.Provider 101 } 102 103 if requirements.Kaniko { 104 if provider == cloud.GKE { 105 err = o.validateKaniko(ns) 106 if err != nil { 107 return err 108 } 109 } 110 } 111 log.Logger().Infof("Installation is currently looking: %s\n", util.ColorInfo("GOOD")) 112 return nil 113 }