Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
Signed-off-by: Stephanie <yangcao@redhat.com>
  • Loading branch information
yangcao77 committed Nov 13, 2023
2 parents d7350e8 + 0818fb9 commit 5a02383
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 32 deletions.
34 changes: 16 additions & 18 deletions cdq-analysis/pkg/componentdetectionquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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))
Expand All @@ -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
}
}
Expand All @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion cdq-analysis/pkg/componentdetectionquery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions pkg/devfile/devfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions pkg/devfile/devfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down

0 comments on commit 5a02383

Please sign in to comment.