소스 검색

Merge pull request #1961 from porter-dev/nafees/hotfixes

[hotfix] Ephemeral pods deletion cronjob should run in the `default` namespace
abelanger5 4 년 전
부모
커밋
07b971f426
2개의 변경된 파일17개의 추가작업 그리고 4개의 파일을 삭제
  1. 2 2
      api/server/shared/commonutils/git_utils.go
  2. 15 2
      cli/cmd/run.go

+ 2 - 2
api/server/shared/commonutils/git_utils.go

@@ -22,7 +22,7 @@ func GetLatestWorkflowRun(client *github.Client, owner, repo, filename, branch s
 		},
 	)
 
-	if ghResponse.StatusCode == http.StatusNotFound {
+	if ghResponse != nil && ghResponse.StatusCode == http.StatusNotFound {
 		return nil, ErrWorkflowNotFound
 	}
 
@@ -30,7 +30,7 @@ func GetLatestWorkflowRun(client *github.Client, owner, repo, filename, branch s
 		return nil, err
 	}
 
-	if workflowRuns.GetTotalCount() == 0 {
+	if workflowRuns == nil || workflowRuns.GetTotalCount() == 0 {
 		return nil, ErrNoWorkflowRuns
 	}
 

+ 15 - 2
cli/cmd/run.go

@@ -498,8 +498,21 @@ func checkForPodDeletionCronJob(config *PorterRunSharedConfig) error {
 			return err
 		}
 
+		if namespace.Name != "default" {
+			for _, cronJob := range cronJobs.Items {
+				if cronJob.Name == "porter-ephemeral-pod-deletion-cronjob" {
+					err = config.Clientset.BatchV1beta1().CronJobs(namespace.Name).Delete(
+						context.Background(), cronJob.Name, metav1.DeleteOptions{},
+					)
+					if err != nil {
+						return err
+					}
+				}
+			}
+		}
+
 		for _, cronJob := range cronJobs.Items {
-			if cronJob.Name == "porter-ephemeral-pod-deletion-cronjob" {
+			if namespace.Name == "default" && cronJob.Name == "porter-ephemeral-pod-deletion-cronjob" {
 				return nil
 			}
 		}
@@ -551,7 +564,7 @@ func checkForPodDeletionCronJob(config *PorterRunSharedConfig) error {
 			},
 		},
 	}
-	_, err = config.Clientset.BatchV1beta1().CronJobs(namespace).Create(
+	_, err = config.Clientset.BatchV1beta1().CronJobs("default").Create(
 		context.Background(), cronJob, metav1.CreateOptions{},
 	)
 	if err != nil {