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

feat: check sa before start a job #2024

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Changes from all commits
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
20 changes: 19 additions & 1 deletion pkg/controller/job-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/minio/minio-go/v7/pkg/set"
"github.com/minio/operator/pkg/apis/job.min.io/v1alpha1"
miniov2 "github.com/minio/operator/pkg/apis/minio.min.io/v2"
stsv1alpha1 "github.com/minio/operator/pkg/apis/sts.min.io/v1alpha1"
clientset "github.com/minio/operator/pkg/client/clientset/versioned"
jobinformers "github.com/minio/operator/pkg/client/informers/externalversions/job.min.io/v1alpha1"
joblisters "github.com/minio/operator/pkg/client/listers/job.min.io/v1alpha1"
Expand Down Expand Up @@ -246,7 +247,24 @@ func (c *JobController) SyncHandler(key string) (Result, error) {
if tenant.Status.HealthStatus != miniov2.HealthStatusGreen {
return WrapResult(Result{RequeueAfter: time.Second * 5}, nil)
}
fmt.Println("will do somthing next")
// check sa
pbs := &stsv1alpha1.PolicyBindingList{}
err = c.k8sClient.List(ctx, pbs, client.InNamespace(namespace))
if err != nil {
return WrapResult(Result{}, err)
}
if len(pbs.Items) == 0 {
return WrapResult(Result{}, fmt.Errorf("no policybinding found"))
}
saFound := false
for _, pb := range pbs.Items {
if pb.Spec.Application.Namespace == namespace && pb.Spec.Application.ServiceAccount == jobCR.Spec.ServiceAccountName {
saFound = true
}
}
if !saFound {
return WrapResult(Result{}, fmt.Errorf("no serviceaccount found"))
}
// Loop through the different supported operations.
for _, val := range jobCR.Spec.Commands {
operation := val.Operation
Expand Down
Loading