From 730fae034461e77d1d9db05d64a968fee879382b Mon Sep 17 00:00:00 2001 From: jiuker Date: Tue, 6 Aug 2024 20:55:31 +0800 Subject: [PATCH 1/3] add support not tls add support not tls --- pkg/controller/job-controller.go | 2 +- pkg/utils/miniojob/types.go | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/controller/job-controller.go b/pkg/controller/job-controller.go index e04446b7340..642ba1c612d 100644 --- a/pkg/controller/job-controller.go +++ b/pkg/controller/job-controller.go @@ -268,7 +268,7 @@ func (c *JobController) SyncHandler(key string) (_ Result, err error) { if err != nil { return WrapResult(Result{}, err) } - err = intervalJob.CreateCommandJob(ctx, c.k8sClient, STSDefaultPort) + err = intervalJob.CreateCommandJob(ctx, c.k8sClient, STSDefaultPort, tenant.TLS()) if err != nil { return WrapResult(Result{}, fmt.Errorf("create job error: %w", err)) } diff --git a/pkg/utils/miniojob/types.go b/pkg/utils/miniojob/types.go index d541a7d9d2e..4f8fdc92285 100644 --- a/pkg/utils/miniojob/types.go +++ b/pkg/utils/miniojob/types.go @@ -118,7 +118,7 @@ func (jobCommand *MinIOIntervalJobCommand) Success() bool { } // createJob - create job -func (jobCommand *MinIOIntervalJobCommand) createJob(_ context.Context, _ client.Client, jobCR *v1alpha1.MinIOJob, stsPort int) (objs []client.Object) { +func (jobCommand *MinIOIntervalJobCommand) createJob(_ context.Context, _ client.Client, jobCR *v1alpha1.MinIOJob, stsPort int, isTLS bool) (objs []client.Object) { if jobCommand == nil { return nil } @@ -172,13 +172,17 @@ func (jobCommand *MinIOIntervalJobCommand) createJob(_ context.Context, _ client }, } baseEnvFrom = append(baseEnvFrom, jobCommand.CommandSpec.EnvFrom...) + urlProtocol := "http://" + if isTLS { + urlProtocol = "https://" + } secret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%s-job-secret", jobCR.Name), Namespace: jobCR.Namespace, }, StringData: map[string]string{ - "MC_HOST_myminio": fmt.Sprintf("https://$(ACCESS_KEY):$(SECRET_KEY)@minio.%s.svc.cluster.local", jobCR.Namespace), + "MC_HOST_myminio": fmt.Sprintf("%s$(ACCESS_KEY):$(SECRET_KEY)@minio.%s.svc.cluster.local", urlProtocol, jobCR.Namespace), "MC_STS_ENDPOINT_myminio": fmt.Sprintf("https://sts.%s.svc.cluster.local:%d/sts/%s", miniov2.GetNSFromFile(), stsPort, jobCR.Namespace), "MC_WEB_IDENTITY_TOKEN_FILE_myminio": "/var/run/secrets/kubernetes.io/serviceaccount/token", }, @@ -235,8 +239,8 @@ func (jobCommand *MinIOIntervalJobCommand) createJob(_ context.Context, _ client } // CreateJob - create job -func (jobCommand *MinIOIntervalJobCommand) CreateJob(ctx context.Context, k8sClient client.Client, jobCR *v1alpha1.MinIOJob, stsPort int) error { - for _, obj := range jobCommand.createJob(ctx, k8sClient, jobCR, stsPort) { +func (jobCommand *MinIOIntervalJobCommand) CreateJob(ctx context.Context, k8sClient client.Client, jobCR *v1alpha1.MinIOJob, stsPort int, isTLS bool) error { + for _, obj := range jobCommand.createJob(ctx, k8sClient, jobCR, stsPort, isTLS) { if obj == nil { continue } @@ -310,10 +314,10 @@ func (intervalJob *MinIOIntervalJob) GetMinioJobStatus(_ context.Context) v1alph } // CreateCommandJob - create command job -func (intervalJob *MinIOIntervalJob) CreateCommandJob(ctx context.Context, k8sClient client.Client, stsPort int) error { +func (intervalJob *MinIOIntervalJob) CreateCommandJob(ctx context.Context, k8sClient client.Client, stsPort int, isTLS bool) error { for _, command := range intervalJob.Command { if len(command.CommandSpec.DependsOn) == 0 { - err := command.CreateJob(ctx, k8sClient, intervalJob.JobCR, stsPort) + err := command.CreateJob(ctx, k8sClient, intervalJob.JobCR, stsPort, isTLS) if err != nil { return err } @@ -330,7 +334,7 @@ func (intervalJob *MinIOIntervalJob) CreateCommandJob(ctx context.Context, k8sCl } } if allDepsSuccess { - err := command.CreateJob(ctx, k8sClient, intervalJob.JobCR, stsPort) + err := command.CreateJob(ctx, k8sClient, intervalJob.JobCR, stsPort, isTLS) if err != nil { return err } From 38b0e0db6e86ca26eb97506356e29d34c532b181 Mon Sep 17 00:00:00 2001 From: jiuker Date: Wed, 7 Aug 2024 09:11:52 +0800 Subject: [PATCH 2/3] apply suggestion apply suggestion --- pkg/utils/miniojob/types.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/utils/miniojob/types.go b/pkg/utils/miniojob/types.go index 4f8fdc92285..70bad3ef311 100644 --- a/pkg/utils/miniojob/types.go +++ b/pkg/utils/miniojob/types.go @@ -172,9 +172,9 @@ func (jobCommand *MinIOIntervalJobCommand) createJob(_ context.Context, _ client }, } baseEnvFrom = append(baseEnvFrom, jobCommand.CommandSpec.EnvFrom...) - urlProtocol := "http://" + scheme := "http://" if isTLS { - urlProtocol = "https://" + scheme = "https://" } secret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ @@ -182,8 +182,8 @@ func (jobCommand *MinIOIntervalJobCommand) createJob(_ context.Context, _ client Namespace: jobCR.Namespace, }, StringData: map[string]string{ - "MC_HOST_myminio": fmt.Sprintf("%s$(ACCESS_KEY):$(SECRET_KEY)@minio.%s.svc.cluster.local", urlProtocol, jobCR.Namespace), - "MC_STS_ENDPOINT_myminio": fmt.Sprintf("https://sts.%s.svc.cluster.local:%d/sts/%s", miniov2.GetNSFromFile(), stsPort, jobCR.Namespace), + "MC_HOST_myminio": fmt.Sprintf("%s$(ACCESS_KEY):$(SECRET_KEY)@minio.%s.svc.%s", scheme, jobCR.Namespace, miniov2.GetClusterDomain()), + "MC_STS_ENDPOINT_myminio": fmt.Sprintf("https://sts.%s.svc.%s:%d/sts/%s", miniov2.GetNSFromFile(), miniov2.GetClusterDomain(), stsPort, jobCR.Namespace), "MC_WEB_IDENTITY_TOKEN_FILE_myminio": "/var/run/secrets/kubernetes.io/serviceaccount/token", }, } From c4ceb8dece9cd90b1b9496536c990e20f9debc8a Mon Sep 17 00:00:00 2001 From: jiuker Date: Thu, 8 Aug 2024 08:58:46 +0800 Subject: [PATCH 3/3] apply suggestion apply suggestion --- pkg/utils/miniojob/types.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/utils/miniojob/types.go b/pkg/utils/miniojob/types.go index 70bad3ef311..f01ce1d8183 100644 --- a/pkg/utils/miniojob/types.go +++ b/pkg/utils/miniojob/types.go @@ -172,9 +172,9 @@ func (jobCommand *MinIOIntervalJobCommand) createJob(_ context.Context, _ client }, } baseEnvFrom = append(baseEnvFrom, jobCommand.CommandSpec.EnvFrom...) - scheme := "http://" + scheme := "http" if isTLS { - scheme = "https://" + scheme = "https" } secret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ @@ -182,7 +182,7 @@ func (jobCommand *MinIOIntervalJobCommand) createJob(_ context.Context, _ client Namespace: jobCR.Namespace, }, StringData: map[string]string{ - "MC_HOST_myminio": fmt.Sprintf("%s$(ACCESS_KEY):$(SECRET_KEY)@minio.%s.svc.%s", scheme, jobCR.Namespace, miniov2.GetClusterDomain()), + "MC_HOST_myminio": fmt.Sprintf("%s://$(ACCESS_KEY):$(SECRET_KEY)@minio.%s.svc.%s", scheme, jobCR.Namespace, miniov2.GetClusterDomain()), "MC_STS_ENDPOINT_myminio": fmt.Sprintf("https://sts.%s.svc.%s:%d/sts/%s", miniov2.GetNSFromFile(), miniov2.GetClusterDomain(), stsPort, jobCR.Namespace), "MC_WEB_IDENTITY_TOKEN_FILE_myminio": "/var/run/secrets/kubernetes.io/serviceaccount/token", },