From 4d209ef89d7fd821c2f4daa618a5df6a307ffcb3 Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Wed, 28 Nov 2018 17:51:48 +0100 Subject: [PATCH 1/4] chore(upgrade ingress): wrap some errors with relevant messages to make debugging easier --- pkg/jx/cmd/upgrade_ingress.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/pkg/jx/cmd/upgrade_ingress.go b/pkg/jx/cmd/upgrade_ingress.go index 2faa4632a9..d22ebad432 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" @@ -101,24 +102,24 @@ 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 + 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 +133,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,7 +165,7 @@ func (o *UpgradeIngressOptions) Run() error { err = o.recreateIngressRules() if err != nil { - return err + return errors.Wrap(err, "recreating the ingress rules") } _, _, err = o.JXClient() @@ -174,13 +175,13 @@ func (o *UpgradeIngressOptions) Run() error { 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? @@ -197,12 +198,11 @@ func (o *UpgradeIngressOptions) Run() error { 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 +213,6 @@ func (o *UpgradeIngressOptions) Run() error { if updateWebHooks { o.updateWebHooks(previousWebHookEndpoint, updatedWebHookEndpoint) } - return nil } From 80b97736af20f8282b84d1fc686220ad5c8e6ca2 Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Wed, 28 Nov 2018 18:11:26 +0100 Subject: [PATCH 2/4] refactor(upgrade ingress): add a flag to skip the update of jx related resources This allows to run the command 'upgrade ingress' before the jx installation. --- pkg/jx/cmd/upgrade_ingress.go | 57 +++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/pkg/jx/cmd/upgrade_ingress.go b/pkg/jx/cmd/upgrade_ingress.go index d22ebad432..0232f1329d 100644 --- a/pkg/jx/cmd/upgrade_ingress.go +++ b/pkg/jx/cmd/upgrade_ingress.go @@ -41,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 + SkipJxResourcesUpdate bool IngressConfig kube.IngressConfig } @@ -90,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.SkipJxResourcesUpdate, "skip-jx-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) @@ -104,10 +105,12 @@ func (o *UpgradeIngressOptions) Run() error { if err != nil { return errors.Wrap(err, "getting the dev namesapce") } - - previousWebHookEndpoint, err := o.GetWebHookEndpoint() - if err != nil { - return errors.Wrap(err, "getting the webhook endpoint") + previousWebHookEndpoint := "" + if !o.SkipJxResourcesUpdate { + 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? @@ -168,7 +171,26 @@ func (o *UpgradeIngressOptions) Run() error { return errors.Wrap(err, "recreating the ingress rules") } - _, _, err = o.JXClient() + if !o.SkipJxResourcesUpdate { + o.updateJxResources(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) updateJxResources(previousWebHookEndpoint string) error { + _, _, err := o.JXClient() if err != nil { return errors.Wrap(err, "failed to get jxclient") } @@ -184,17 +206,6 @@ func (o *UpgradeIngressOptions) Run() error { 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 { From f4b778d6b537c2bd825bc2b637f4fb35b3211866 Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Wed, 28 Nov 2018 18:12:42 +0100 Subject: [PATCH 3/4] fix(vault): skip the update of jx related resource when exposing the vault --- pkg/jx/cmd/create_vault.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/jx/cmd/create_vault.go b/pkg/jx/cmd/create_vault.go index 947f559c6a..3c2c7c093b 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.SkipJxResourcesUpdate = true return options.Run() } From ddbf0bd7242cd409ff4e8d920d86e8ef50f77121 Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Wed, 28 Nov 2018 18:20:44 +0100 Subject: [PATCH 4/4] refactor: remove the jx from the option name and renamted the related variables and function --- pkg/jx/cmd/create_vault.go | 2 +- pkg/jx/cmd/upgrade_ingress.go | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/jx/cmd/create_vault.go b/pkg/jx/cmd/create_vault.go index 3c2c7c093b..739afbc69b 100644 --- a/pkg/jx/cmd/create_vault.go +++ b/pkg/jx/cmd/create_vault.go @@ -260,6 +260,6 @@ func (o *CreateVaultOptions) exposeVault(vaultService string) error { options := &o.UpgradeIngressOptions options.Namespaces = []string{o.Namespace} options.Services = []string{vaultService} - options.SkipJxResourcesUpdate = true + options.SkipResourcesUpdate = true return options.Run() } diff --git a/pkg/jx/cmd/upgrade_ingress.go b/pkg/jx/cmd/upgrade_ingress.go index 0232f1329d..1bffb9e3d4 100644 --- a/pkg/jx/cmd/upgrade_ingress.go +++ b/pkg/jx/cmd/upgrade_ingress.go @@ -41,13 +41,13 @@ const ( type UpgradeIngressOptions struct { CreateOptions - SkipCertManager bool - Cluster bool - Namespaces []string - Version string - TargetNamespaces []string - Services []string - SkipJxResourcesUpdate bool + SkipCertManager bool + Cluster bool + Namespaces []string + Version string + TargetNamespaces []string + Services []string + SkipResourcesUpdate bool IngressConfig kube.IngressConfig } @@ -91,7 +91,7 @@ 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.SkipJxResourcesUpdate, "skip-jx-resources-update", "", false, "Skips the update of jx related resources such as webhook or Jenkins URL") + 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 @@ -106,7 +106,7 @@ func (o *UpgradeIngressOptions) Run() error { return errors.Wrap(err, "getting the dev namesapce") } previousWebHookEndpoint := "" - if !o.SkipJxResourcesUpdate { + if !o.SkipResourcesUpdate { previousWebHookEndpoint, err = o.GetWebHookEndpoint() if err != nil { return errors.Wrap(err, "getting the webhook endpoint") @@ -171,8 +171,8 @@ func (o *UpgradeIngressOptions) Run() error { return errors.Wrap(err, "recreating the ingress rules") } - if !o.SkipJxResourcesUpdate { - o.updateJxResources(previousWebHookEndpoint) + if !o.SkipResourcesUpdate { + o.updateResources(previousWebHookEndpoint) } log.Success("Ingress rules recreated\n") @@ -189,7 +189,7 @@ func (o *UpgradeIngressOptions) Run() error { return nil } -func (o *UpgradeIngressOptions) updateJxResources(previousWebHookEndpoint string) error { +func (o *UpgradeIngressOptions) updateResources(previousWebHookEndpoint string) error { _, _, err := o.JXClient() if err != nil { return errors.Wrap(err, "failed to get jxclient")