Skip to content

Commit baccdf6

Browse files
jiukerguozhi.li
andauthored
feat: check sa before start a job (#2024)
* check sa before start a job check sa before start a job * import * apply suggestion --------- Co-authored-by: guozhi.li <guozhi.li@daocloud.io>
1 parent 306afd6 commit baccdf6

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pkg/controller/job-controller.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/minio/minio-go/v7/pkg/set"
1212
"github.com/minio/operator/pkg/apis/job.min.io/v1alpha1"
1313
miniov2 "github.com/minio/operator/pkg/apis/minio.min.io/v2"
14+
stsv1alpha1 "github.com/minio/operator/pkg/apis/sts.min.io/v1alpha1"
1415
clientset "github.com/minio/operator/pkg/client/clientset/versioned"
1516
jobinformers "github.com/minio/operator/pkg/client/informers/externalversions/job.min.io/v1alpha1"
1617
joblisters "github.com/minio/operator/pkg/client/listers/job.min.io/v1alpha1"
@@ -179,7 +180,24 @@ func (c *JobController) SyncHandler(key string) (Result, error) {
179180
if tenant.Status.HealthStatus != miniov2.HealthStatusGreen {
180181
return WrapResult(Result{RequeueAfter: time.Second * 5}, nil)
181182
}
182-
fmt.Println("will do somthing next")
183+
// check sa
184+
pbs := &stsv1alpha1.PolicyBindingList{}
185+
err = c.k8sClient.List(ctx, pbs, client.InNamespace(namespace))
186+
if err != nil {
187+
return WrapResult(Result{}, err)
188+
}
189+
if len(pbs.Items) == 0 {
190+
return WrapResult(Result{}, fmt.Errorf("no policybinding found"))
191+
}
192+
saFound := false
193+
for _, pb := range pbs.Items {
194+
if pb.Spec.Application.Namespace == namespace && pb.Spec.Application.ServiceAccount == jobCR.Spec.ServiceAccountName {
195+
saFound = true
196+
}
197+
}
198+
if !saFound {
199+
return WrapResult(Result{}, fmt.Errorf("no serviceaccount found"))
200+
}
183201
// Loop through the different supported operations.
184202
for _, val := range jobCR.Spec.Commands {
185203
operation := val.Operation

0 commit comments

Comments
 (0)