diff --git a/pkg/cmd/verify/deployments.go b/pkg/cmd/verify/deployments.go index 12a9dd2..6898fb6 100644 --- a/pkg/cmd/verify/deployments.go +++ b/pkg/cmd/verify/deployments.go @@ -13,14 +13,16 @@ import ( ) const defaultTimeout = 2 * time.Minute + var defaultInstallationNamespace = "cert-manager" type Options struct { - ConfigFlags *genericclioptions.ConfigFlags - Streams *genericclioptions.IOStreams - DebugLogs bool + ConfigFlags *genericclioptions.ConfigFlags + Streams *genericclioptions.IOStreams + DebugLogs bool CertManagerNamespace string - Timeout time.Duration + DeploymentPrefix string + Timeout time.Duration } func NewOptions() *Options { @@ -55,6 +57,7 @@ func NewCmd() *cobra.Command { rootCmd.Flags().BoolVar(&options.DebugLogs, "debug", false, "If true, will print out debug logs (default false)") rootCmd.Flags().StringVarP(&options.CertManagerNamespace, "namespace", "n", defaultInstallationNamespace, "Namespace in which cert-manager is installed") rootCmd.Flags().DurationVar(&options.Timeout, "timeout", defaultTimeout, "Timeout after which we give up waiting for cert-manager to be ready.") + rootCmd.Flags().StringVarP(&options.DeploymentPrefix, "prefix", "p", "", "Prefix for the cert-manager deployment names. Default is empty") options.ConfigFlags.AddFlags(rootCmd.Flags()) rootCmd.SetOut(options.Streams.Out) @@ -83,6 +86,7 @@ func (o *Options) Execute() error { logrus.Infof("Waiting for deployments in namespace %s:\n", o.CertManagerNamespace) result, err := verify.Verify(ctx, config, &verify.Options{ o.CertManagerNamespace, + o.DeploymentPrefix, }) if err != nil { return err diff --git a/pkg/verify/deployment.go b/pkg/verify/deployment.go index 650fa17..d4e1d4d 100644 --- a/pkg/verify/deployment.go +++ b/pkg/verify/deployment.go @@ -26,13 +26,19 @@ type Deployment struct { Required bool } -func DeploymentDefinitionDefault(namespace string) DeploymentDefinition { +func DeploymentDefinitionDefault(namespace, deploymentPrefix string) DeploymentDefinition { // TODO make sure these Deployments work also with helm chart installation // TODO make sure we support cert-manager that does not have all these deployments - return DeploymentDefinition{ + def := DeploymentDefinition{ Namespace: namespace, Deployments: []Deployment{{"cert-manager", true}, {"cert-manager-cainjector", false}, {"cert-manager-webhook", false}}, } + if deploymentPrefix != "" { + for _, d := range def.Deployments { + d.Name = deploymentPrefix + d.Name + } + } + return def } type DeploymentResult struct { diff --git a/pkg/verify/verify.go b/pkg/verify/verify.go index 5fe21b3..579a5a4 100644 --- a/pkg/verify/verify.go +++ b/pkg/verify/verify.go @@ -3,6 +3,7 @@ package verify import ( "context" "fmt" + "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" @@ -15,16 +16,17 @@ type VerifyResult struct { CertificateSuccess bool DeploymentsResult []DeploymentResult - CertificateError error + CertificateError error } type CertificateResult struct { Success bool - Error error + Error error } type Options struct { CertManagerNamespace string + DeploymentPrefix string } func Verify(ctx context.Context, config *rest.Config, options *Options) (*VerifyResult, error) { @@ -37,11 +39,11 @@ func Verify(ctx context.Context, config *rest.Config, options *Options) (*Verify return nil, fmt.Errorf("unable to get kubernetes client: %v", err) } - deployments := DeploymentDefinitionDefault(options.CertManagerNamespace) + deployments := DeploymentDefinitionDefault(options.CertManagerNamespace, options.DeploymentPrefix) deploymentResult := DeploymentsReady(ctx, kubeClient, deployments) result := &VerifyResult{ - Success: false, + Success: false, DeploymentsResult: deploymentResult, }