diff --git a/pkg/jx/cmd/create_vault.go b/pkg/jx/cmd/create_vault.go index 947f559c6a..739afbc69b 100644 --- a/pkg/jx/cmd/create_vault.go +++ b/pkg/jx/cmd/create_vault.go @@ -2,11 +2,11 @@ package cmd import ( "fmt" - "github.com/banzaicloud/bank-vaults/operator/pkg/client/clientset/versioned" - "github.com/jenkins-x/jx/pkg/kube/services" "io" "time" + "github.com/banzaicloud/bank-vaults/operator/pkg/client/clientset/versioned" + "github.com/jenkins-x/jx/pkg/kube/services" "github.com/pkg/errors" "github.com/spf13/cobra" "gopkg.in/AlecAivazis/survey.v1/terminal" @@ -260,5 +260,6 @@ func (o *CreateVaultOptions) exposeVault(vaultService string) error { options := &o.UpgradeIngressOptions options.Namespaces = []string{o.Namespace} options.Services = []string{vaultService} + options.SkipResourcesUpdate = true return options.Run() } diff --git a/pkg/jx/cmd/upgrade_ingress.go b/pkg/jx/cmd/upgrade_ingress.go index 2faa4632a9..1bffb9e3d4 100644 --- a/pkg/jx/cmd/upgrade_ingress.go +++ b/pkg/jx/cmd/upgrade_ingress.go @@ -2,11 +2,12 @@ package cmd import ( "fmt" + "io" + "strings" + "github.com/jenkins-x/jx/pkg/gits" "github.com/jenkins-x/jx/pkg/kube/services" "github.com/pkg/errors" - "io" - "strings" "github.com/jenkins-x/jx/pkg/jx/cmd/templates" "github.com/jenkins-x/jx/pkg/kube" @@ -40,12 +41,13 @@ const ( type UpgradeIngressOptions struct { CreateOptions - SkipCertManager bool - Cluster bool - Namespaces []string - Version string - TargetNamespaces []string - Services []string + SkipCertManager bool + Cluster bool + Namespaces []string + Version string + TargetNamespaces []string + Services []string + SkipResourcesUpdate bool IngressConfig kube.IngressConfig } @@ -89,11 +91,11 @@ func (o *UpgradeIngressOptions) addFlags(cmd *cobra.Command) { cmd.Flags().StringArrayVarP(&o.Namespaces, "namespaces", "", []string{}, "Namespaces to upgrade") cmd.Flags().BoolVarP(&o.SkipCertManager, "skip-certmanager", "", false, "Skips certmanager installation") cmd.Flags().StringArrayVarP(&o.Services, "services", "", []string{}, "Services to upgrdde") + cmd.Flags().BoolVarP(&o.SkipResourcesUpdate, "skip-resources-update", "", false, "Skips the update of jx related resources such as webhook or Jenkins URL") } // Run implements the command func (o *UpgradeIngressOptions) Run() error { - _, _, err := o.KubeClient() if err != nil { return fmt.Errorf("cannot connect to Kubernetes cluster: %v", err) @@ -101,24 +103,26 @@ func (o *UpgradeIngressOptions) Run() error { o.devNamespace, _, err = kube.GetDevNamespace(o.KubeClientCached, o.currentNamespace) if err != nil { - return err + return errors.Wrap(err, "getting the dev namesapce") } - - previousWebHookEndpoint, err := o.GetWebHookEndpoint() - if err != nil { - return err + previousWebHookEndpoint := "" + if !o.SkipResourcesUpdate { + previousWebHookEndpoint, err = o.GetWebHookEndpoint() + if err != nil { + return errors.Wrap(err, "getting the webhook endpoint") + } } // if existing ingress exist in the namespaces ask do you want to delete them? ingressToDelete, err := o.getExistingIngressRules() if err != nil { - return err + return errors.Wrap(err, "getting the existing ingress rules") } // wizard to ask for config values err = o.confirmExposecontrollerConfig() if err != nil { - return err + return errors.Wrap(err, "configure exposecontroller") } // confirm values @@ -132,25 +136,25 @@ func (o *UpgradeIngressOptions) Run() error { // save details to a configmap _, err = kube.SaveAsConfigMap(o.KubeClientCached, kube.ConfigMapIngressConfig, o.devNamespace, o.IngressConfig) if err != nil { - return err + return errors.Wrap(err, "saving ingress config into a configmap") } err = o.CleanServiceAnnotations(o.Services...) if err != nil { - return err + return errors.Wrap(err, "cleaning service annotations") } // if tls create CRDs if o.IngressConfig.TLS { err = o.ensureCertmanagerSetup() if err != nil { - return err + return errors.Wrap(err, "ensure cert-manager setup") } } // annotate any service that has expose=true with correct certmanager staging / prod annotation err = o.AnnotateExposedServicesWithCertManager(o.Services...) if err != nil { - return err + return errors.Wrap(err, "annotating the exposed service with cert-manager") } // delete ingress @@ -164,45 +168,52 @@ func (o *UpgradeIngressOptions) Run() error { err = o.recreateIngressRules() if err != nil { - return err + return errors.Wrap(err, "recreating the ingress rules") } - _, _, err = o.JXClient() + if !o.SkipResourcesUpdate { + o.updateResources(previousWebHookEndpoint) + } + + log.Success("Ingress rules recreated\n") + + // todo wait for certs secrets to update ingress rules? + if o.IngressConfig.TLS { + log.Warn("It can take around 5 minutes for Cert Manager to get certificates from Lets Encrypt and update Ingress rules\n") + log.Info("Use the following commands to diagnose any issues:\n") + log.Infof("jx logs %s -n %s\n", CertManagerDeployment, CertManagerNamespace) + log.Info("kubectl describe certificates\n") + log.Info("kubectl describe issuers\n\n") + } + + return nil +} + +func (o *UpgradeIngressOptions) updateResources(previousWebHookEndpoint string) error { + _, _, err := o.JXClient() if err != nil { return errors.Wrap(err, "failed to get jxclient") } isProwEnabled, err := o.isProw() if err != nil { - return err + return errors.Wrap(err, "checking if is prow") } if !isProwEnabled { err = o.updateJenkinsURL(o.TargetNamespaces) if err != nil { - return err + return errors.Wrap(err, "upgrade jenkins URL") } } - // todo wait for certs secrets to update ingress rules? - - log.Success("Ingress rules recreated\n") - - if o.IngressConfig.TLS { - log.Warn("It can take around 5 minutes for Cert Manager to get certificates from Lets Encrypt and update Ingress rules\n") - log.Info("Use the following commands to diagnose any issues:\n") - log.Infof("jx logs %s -n %s\n", CertManagerDeployment, CertManagerNamespace) - log.Info("kubectl describe certificates\n") - log.Info("kubectl describe issuers\n\n") - } updatedWebHookEndpoint, err := o.GetWebHookEndpoint() if err != nil { - return err + return errors.Wrap(err, "retrieving the webhook endpoint") } log.Infof("Previous webhook endpoint %s\n", previousWebHookEndpoint) log.Infof("Updated webhook endpoint %s\n", updatedWebHookEndpoint) - updateWebHooks := true if !o.BatchMode { if !util.Confirm("Do you want to update all existing webhooks?", true, "", o.In, o.Out, o.Err) { @@ -213,7 +224,6 @@ func (o *UpgradeIngressOptions) Run() error { if updateWebHooks { o.updateWebHooks(previousWebHookEndpoint, updatedWebHookEndpoint) } - return nil }