Skip to content

Commit

Permalink
Add support for deployment prefix (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
alenkacz committed Apr 23, 2021
1 parent 825cec0 commit cbbc833
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
12 changes: 8 additions & 4 deletions pkg/cmd/verify/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions pkg/verify/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

This comment has been minimized.

Copy link
@inteon

inteon Jun 19, 2021

I think this line contains an error: by looping over the values by value, the values are copied and thus the changes are not reflected in the original "def" value.
@alenkacz

d.Name = deploymentPrefix + d.Name
}
}
return def
}

type DeploymentResult struct {
Expand Down
10 changes: 6 additions & 4 deletions pkg/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package verify
import (
"context"
"fmt"

"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand All @@ -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) {
Expand All @@ -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,
}

Expand Down

0 comments on commit cbbc833

Please sign in to comment.