From d02980242dd9e1246e34ee3af03b8d0bead069c3 Mon Sep 17 00:00:00 2001 From: Raphael Ludwig Date: Tue, 3 May 2022 10:02:16 +0200 Subject: [PATCH] refactor: Remove service account check Signed-off-by: Raphael Ludwig --- pkg/eventhandler/eventhandlers.go | 18 ------------------ pkg/k8sutils/job.go | 10 ---------- 2 files changed, 28 deletions(-) diff --git a/pkg/eventhandler/eventhandlers.go b/pkg/eventhandler/eventhandlers.go index 683bc445..8604d7ff 100644 --- a/pkg/eventhandler/eventhandlers.go +++ b/pkg/eventhandler/eventhandlers.go @@ -57,7 +57,6 @@ type K8s interface { jobName string, maxPollDuration time.Duration, pollIntervalInSeconds time.Duration, namespace string, ) error GetLogsOfPod(jobName string, namespace string) (string, error) - ExistsServiceAccount(saName string, namespace string) bool } // EventHandler contains all information needed to process an event @@ -162,12 +161,6 @@ func (eh *EventHandler) startK8sJob(action *config.Action, jsonEventData interfa // To execute all tasks atomically, we check all images before we start executing a single task of a job // Additionally we want to check if the job configuration is sound (like validating the specified serviceAccounts) for _, task := range action.Tasks { - - namespace := eh.JobSettings.JobNamespace - if len(task.Namespace) > 0 { - namespace = task.Namespace - } - if !eh.ImageFilter.IsImageAllowed(task.Image) { errorText := fmt.Sprintf("Forbidden: Image %s does not match configured image allowlist.\n", task.Image) @@ -178,17 +171,6 @@ func (eh *EventHandler) startK8sJob(action *config.Action, jsonEventData interfa return } - - if task.ServiceAccount != nil && !eh.K8s.ExistsServiceAccount(*task.ServiceAccount, namespace) { - errorText := fmt.Sprintf("Error: service account %s does not exist!\n", *task.ServiceAccount) - - log.Printf(errorText) - if !action.Silent { - sendTaskFailedEvent(eh.Keptn, task.Name, eh.ServiceName, errors.New(errorText), "") - } - - return - } } for index, task := range action.Tasks { diff --git a/pkg/k8sutils/job.go b/pkg/k8sutils/job.go index 4e712c00..6a69af6a 100644 --- a/pkg/k8sutils/job.go +++ b/pkg/k8sutils/job.go @@ -442,13 +442,3 @@ func (k8s *K8sImpl) generateEnvFromSecret(env config.Env, namespace string) ([]v return generatedEnv, nil } - -// ExistsServiceAccount returns true of the given service account exists in the namespace -func (k8s *K8sImpl) ExistsServiceAccount(saName string, namespace string) bool { - _, err := k8s.clientset.CoreV1().ServiceAccounts(namespace).Get(context.TODO(), saName, metav1.GetOptions{}) - if err != nil { - return false - } - - return true -}