Skip to content

Commit

Permalink
fix(util): Change NetworkPolicy to use batch.kubernetes.io/job-name
Browse files Browse the repository at this point in the history
This fixes clusters using the Cilium CNI since `batch.kubernetes.io/controller-uid` is ignored
  • Loading branch information
gabe565 committed May 20, 2024
1 parent ddc2f30 commit b7dd3c2
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions internal/util/cmd_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func createJob(ctx context.Context, conf *config.Global, actionName string) erro
}

if viper.GetBool(consts.CreateNetworkPolicyKey) {
jobPodKey, jobPodVal := jobPodLabel(conf, conf.Job)
jobPodKey, jobPodVal := jobPodNameLabel(conf, conf.Job)
policy := networkingv1.NetworkPolicy{
ObjectMeta: metav1.ObjectMeta{
Name: conf.Job.Name,
Expand Down Expand Up @@ -496,7 +496,7 @@ func pollJobPod(ctx context.Context, conf *config.Global) error {
)
}

func jobPodLabel(conf *config.Global, job *batchv1.Job) (string, string) {
func jobPodUIDLabel(conf *config.Global, job *batchv1.Job) (string, string) {
useNewLabel, err := conf.Client.MinServerVersion(1, 27)
if err != nil {
log.Warn().Err(err).Msg("failed to query server version; assuming v1.27+")
Expand All @@ -513,6 +513,22 @@ func jobPodLabel(conf *config.Global, job *batchv1.Job) (string, string) {
}

func jobPodLabelSelector(conf *config.Global, job *batchv1.Job) string {
k, v := jobPodLabel(conf, job)
k, v := jobPodUIDLabel(conf, job)
return k + "=" + v
}

func jobPodNameLabel(conf *config.Global, job *batchv1.Job) (string, string) {
useNewLabel, err := conf.Client.MinServerVersion(1, 27)
if err != nil {
log.Warn().Err(err).Msg("failed to query server version; assuming v1.27+")
useNewLabel = true
}

var key string
if useNewLabel {
key = "batch.kubernetes.io/job-name"
} else {
key = "job-name"
}
return key, job.Name
}

0 comments on commit b7dd3c2

Please sign in to comment.