From bcf28877b52071cd31251552739dfc8194112a0b Mon Sep 17 00:00:00 2001 From: John Collier Date: Tue, 7 Nov 2023 16:43:40 -0500 Subject: [PATCH 1/2] [RHTAPBUGS-824] Don't overwrite probe ports if they are already set (#409) * [RHTAPBUGS-824] Don't overwrite probe ports if they are already set Signed-off-by: John Collier * Fix typo Signed-off-by: John Collier --------- Signed-off-by: John Collier Co-authored-by: Flavius Lacatusu --- pkg/devfile/devfile.go | 7 ------- pkg/devfile/devfile_test.go | 12 ++++++------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/pkg/devfile/devfile.go b/pkg/devfile/devfile.go index 690e9e012..d438afa34 100644 --- a/pkg/devfile/devfile.go +++ b/pkg/devfile/devfile.go @@ -192,13 +192,6 @@ func GetResourceFromDevfile(log logr.Logger, devfileData data.DevfileData, deplo resources.Deployments[0].Spec.Template.Spec.Containers[0].Ports = append(resources.Deployments[0].Spec.Template.Spec.Containers[0].Ports, containerPort) } - if resources.Deployments[0].Spec.Template.Spec.Containers[0].ReadinessProbe != nil && resources.Deployments[0].Spec.Template.Spec.Containers[0].ReadinessProbe.ProbeHandler.TCPSocket != nil { - resources.Deployments[0].Spec.Template.Spec.Containers[0].ReadinessProbe.ProbeHandler.TCPSocket.Port.IntVal = int32(currentPort) - } - - if resources.Deployments[0].Spec.Template.Spec.Containers[0].LivenessProbe != nil && resources.Deployments[0].Spec.Template.Spec.Containers[0].LivenessProbe.ProbeHandler.HTTPGet != nil { - resources.Deployments[0].Spec.Template.Spec.Containers[0].LivenessProbe.ProbeHandler.HTTPGet.Port.IntVal = int32(currentPort) - } } for _, devfileEnv := range currentENV { diff --git a/pkg/devfile/devfile_test.go b/pkg/devfile/devfile_test.go index 7aa109d34..84f02da3f 100644 --- a/pkg/devfile/devfile_test.go +++ b/pkg/devfile/devfile_test.go @@ -2143,7 +2143,7 @@ schemaVersion: 2.2.0` ProbeHandler: corev1.ProbeHandler{ HTTPGet: &corev1.HTTPGetAction{ Path: "/", - Port: intstr.FromInt(5566), + Port: intstr.FromInt(1111), }, }, InitialDelaySeconds: int32(10), @@ -2160,7 +2160,7 @@ schemaVersion: 2.2.0` ReadinessProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ TCPSocket: &corev1.TCPSocketAction{ - Port: intstr.FromInt(5566), + Port: intstr.FromInt(1111), }, }, InitialDelaySeconds: int32(10), @@ -2347,7 +2347,7 @@ schemaVersion: 2.2.0` ProbeHandler: corev1.ProbeHandler{ HTTPGet: &corev1.HTTPGetAction{ Path: "/", - Port: intstr.FromInt(5566), + Port: intstr.FromInt(1111), }, }, InitialDelaySeconds: int32(10), @@ -2364,7 +2364,7 @@ schemaVersion: 2.2.0` ReadinessProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ TCPSocket: &corev1.TCPSocketAction{ - Port: intstr.FromInt(5566), + Port: intstr.FromInt(1111), }, }, InitialDelaySeconds: int32(10), @@ -3429,7 +3429,7 @@ schemaVersion: 2.2.0` ProbeHandler: corev1.ProbeHandler{ HTTPGet: &corev1.HTTPGetAction{ Path: "/", - Port: intstr.FromInt(5566), + Port: intstr.FromInt(1111), }, }, InitialDelaySeconds: int32(10), @@ -3446,7 +3446,7 @@ schemaVersion: 2.2.0` ReadinessProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ TCPSocket: &corev1.TCPSocketAction{ - Port: intstr.FromInt(5566), + Port: intstr.FromInt(1111), }, }, InitialDelaySeconds: int32(10), From 0818fb9274954f390020b5ec64ffc81036d24d2b Mon Sep 17 00:00:00 2001 From: Stephanie Cao Date: Thu, 9 Nov 2023 11:49:01 -0500 Subject: [PATCH 2/2] [DEVHAS-549]remove clonepath after cdq is done (#412) * remove clonepath after cdq is done Signed-off-by: Stephanie * add back return statement Signed-off-by: Stephanie --------- Signed-off-by: Stephanie --- cdq-analysis/pkg/componentdetectionquery.go | 34 +++++++++---------- .../pkg/componentdetectionquery_test.go | 4 ++- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/cdq-analysis/pkg/componentdetectionquery.go b/cdq-analysis/pkg/componentdetectionquery.go index 9249abf18..18474385a 100644 --- a/cdq-analysis/pkg/componentdetectionquery.go +++ b/cdq-analysis/pkg/componentdetectionquery.go @@ -74,14 +74,14 @@ func (cdqInfo *CDQInfoClient) clone(k K8sInfoClient, namespace, name, context st clonePath, err = CreateTempPath(name, Fs) if err != nil { log.Error(err, fmt.Sprintf("Unable to create a temp path %s for cloning %v", clonePath, namespace)) - k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, err) + k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, clonePath, Fs, err) return err } err = CloneRepo(clonePath, GitURL{RepoURL: repoURL, Revision: revision, Token: gitToken}) if err != nil { log.Error(err, fmt.Sprintf("Unable to clone repo %s to path %s, exiting reconcile loop %v", repoURL, clonePath, namespace)) - k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, err) + k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, clonePath, Fs, err) return err } log.Info(fmt.Sprintf("cloned from %s to path %s... %v", repoURL, clonePath, namespace)) @@ -94,7 +94,7 @@ func (cdqInfo *CDQInfoClient) clone(k K8sInfoClient, namespace, name, context st revision, err = GetBranchFromRepo(componentPath) if err != nil { log.Error(err, fmt.Sprintf("Unable to get branch from cloned repo for component path %s, exiting reconcile loop %v", componentPath, namespace)) - k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, err) + k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, clonePath, Fs, err) return err } } @@ -166,14 +166,14 @@ func CloneAndAnalyze(k K8sInfoClient, namespace, name, context string, cdqInfo * log.Info(fmt.Sprintf("Updating the git link to access devfile: %s ", updatedLink)) if err != nil { log.Error(err, fmt.Sprintf("Unable to update the devfile git link for CDQ %v... %v", name, namespace)) - k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, err) + k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, clonePath, Fs, err) return nil, nil, nil, nil, "", err } shouldIgnoreDevfile, devfileBytes, err := ValidateDevfile(log, updatedLink, gitToken) if err != nil { retErr := &InvalidDevfile{Err: err} - k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, retErr) + k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, clonePath, Fs, retErr) return nil, nil, nil, nil, "", retErr } if shouldIgnoreDevfile { @@ -197,7 +197,7 @@ func CloneAndAnalyze(k K8sInfoClient, namespace, name, context string, cdqInfo * components, err = alizerClient.DetectComponents(componentPath) if err != nil { log.Error(err, fmt.Sprintf("Unable to detect components using Alizer for repo %v, under path %v... %v ", repoURL, componentPath, namespace)) - k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, err) + k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, clonePath, Fs, err) return nil, nil, nil, nil, "", err } log.Info(fmt.Sprintf("components detected %v... %v", components, namespace)) @@ -217,7 +217,7 @@ func CloneAndAnalyze(k K8sInfoClient, namespace, name, context string, cdqInfo * if err != nil { if _, ok := err.(*NoDevfileFound); !ok { log.Error(err, fmt.Sprintf("Unable to find devfile(s) in repo %s due to an error %s, exiting reconcile loop %v", repoURL, err.Error(), namespace)) - k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, err) + k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, clonePath, Fs, err) return nil, nil, nil, nil, "", err } } @@ -226,27 +226,25 @@ func CloneAndAnalyze(k K8sInfoClient, namespace, name, context string, cdqInfo * err := AnalyzePath(log, alizerClient, componentPath, context, registryURL, devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, isDevfilePresent, isDockerfilePresent, gitToken) if err != nil { log.Error(err, fmt.Sprintf("Unable to analyze path %s for a devfile, Dockerfile or Containerfile %v", componentPath, namespace)) - k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, err) + k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, clonePath, Fs, err) return nil, nil, nil, nil, "", err } } - if isExist, _ := IsExisting(Fs, clonePath); isExist { - if err := Fs.RemoveAll(clonePath); err != nil { - log.Error(err, fmt.Sprintf("Unable to remove the clonepath %s %v", clonePath, namespace)) - k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, err) - return nil, nil, nil, nil, "", err - } - } - - k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, nil) + k.SendBackDetectionResult(devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, name, namespace, clonePath, Fs, nil) return devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, revision, nil } -func (k K8sInfoClient) SendBackDetectionResult(devfilesMap map[string][]byte, devfilesURLMap map[string]string, dockerfileContextMap map[string]string, componentPortsMap map[string][]int, revision, name, namespace string, completeError error) { +func (k K8sInfoClient) SendBackDetectionResult(devfilesMap map[string][]byte, devfilesURLMap map[string]string, dockerfileContextMap map[string]string, componentPortsMap map[string][]int, revision, name, namespace, clonePath string, Fs afero.Afero, completeError error) { log := k.Log if !k.CreateK8sJob { log.Info("Skip creating the job...") + // remove the clone path after cdq + if isExist, _ := IsExisting(Fs, clonePath); isExist { + if err := Fs.RemoveAll(clonePath); err != nil { + log.Error(err, fmt.Sprintf("Unable to remove the clonepath %s %v", clonePath, namespace)) + } + } return } log.Info(fmt.Sprintf("Sending back result, devfilesMap %v,devfilesURLMap %v, dockerfileContextMap %v, componentPortsMap %v, error %v ... %v", devfilesMap, devfilesURLMap, dockerfileContextMap, componentPortsMap, completeError, namespace)) diff --git a/cdq-analysis/pkg/componentdetectionquery_test.go b/cdq-analysis/pkg/componentdetectionquery_test.go index 6656343b6..12077a97e 100644 --- a/cdq-analysis/pkg/componentdetectionquery_test.go +++ b/cdq-analysis/pkg/componentdetectionquery_test.go @@ -22,6 +22,7 @@ import ( "reflect" "testing" + "github.com/spf13/afero" "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/fake" @@ -274,6 +275,7 @@ func TestSendBackDetectionResult(t *testing.T) { ctx := context.TODO() clientset := fake.NewSimpleClientset() ctrl.SetLogger(zap.New(zap.UseFlagOptions(&zap.Options{}))) + Fs := afero.Afero{} log := ctrl.Log.WithName("TestSendBackDetectionResult") k8sClient := K8sInfoClient{ @@ -374,7 +376,7 @@ metadata: } for _, tt := range tests { t.Run(tt.testCase, func(t *testing.T) { - k8sClient.SendBackDetectionResult(tt.devfilesMap, tt.devfilesURLMap, tt.dockerfileContextMap, tt.componentPortsMap, revision, compName, namespaceName, tt.err) + k8sClient.SendBackDetectionResult(tt.devfilesMap, tt.devfilesURLMap, tt.dockerfileContextMap, tt.componentPortsMap, revision, compName, namespaceName, "", Fs, tt.err) configMap, err := clientset.CoreV1().ConfigMaps(namespaceName).Get(k8sClient.Ctx, compName, metav1.GetOptions{}) if err != nil { t.Errorf("got unexpected error %v", err)