Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update job name and service name as configurable for cert generator #1889

Merged
merged 4 commits into from
Jun 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add more flags
  • Loading branch information
shaowei su committed Jun 3, 2022
commit a282eae08f0af28b2a7924e7e88740da05f13246
14 changes: 9 additions & 5 deletions pkg/cert-generator/v1beta1/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import (
// generateOptions contains values for all certificates.
type generateOptions struct {
namespace string
service string
job string
fullServiceDomain string
}

Expand All @@ -59,12 +61,14 @@ func NewGenerateCmd(kubeClient client.Client) *cobra.Command {
}
f := cmd.Flags()
f.StringVarP(&o.namespace, "namespace", "n", "kubeflow", "set namespace")
f.StringVarP(&o.job, "job", "j", consts.JobName, "set job name")
f.StringVarP(&o.service, "service", "s", consts.Service, "set service name")
return cmd
}

// run is main function for `generate` subcommand.
func (o *generateOptions) run(ctx context.Context, kubeClient client.Client) error {
o.fullServiceDomain = strings.Join([]string{consts.Service, o.namespace, "svc"}, ".")
o.fullServiceDomain = strings.Join([]string{o.service, o.namespace, "svc"}, ".")

caKeyPair, err := o.createCACert()
if err != nil {
Expand Down Expand Up @@ -127,8 +131,8 @@ func (o *generateOptions) createCert(caKeyPair *certificates) (*certificates, er
CommonName: o.fullServiceDomain,
},
DNSNames: []string{
consts.Service,
strings.Join([]string{consts.Service, o.namespace}, "."),
o.service,
strings.Join([]string{o.service, o.namespace}, "."),
o.fullServiceDomain,
},
NotBefore: now,
Expand Down Expand Up @@ -156,7 +160,7 @@ func (o *generateOptions) createCert(caKeyPair *certificates) (*certificates, er
func (o *generateOptions) createWebhookCertSecret(ctx context.Context, kubeClient client.Client, caKeyPair *certificates, keyPair *certificates) error {

certGeneratorJob := &batchv1.Job{}
if err := kubeClient.Get(ctx, client.ObjectKey{Namespace: o.namespace, Name: consts.JobName}, certGeneratorJob); err != nil {
if err := kubeClient.Get(ctx, client.ObjectKey{Namespace: o.namespace, Name: o.job}, certGeneratorJob); err != nil {
return err
}

Expand All @@ -177,7 +181,7 @@ func (o *generateOptions) createWebhookCertSecret(ctx context.Context, kubeClien
APIVersion: "batch/v1",
Kind: "Job",
Controller: &isController,
Name: consts.JobName,
Name: o.job,
UID: jobUID,
},
},
Expand Down