Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Stephanie <yangcao@redhat.com>
  • Loading branch information
yangcao77 committed Sep 27, 2023
1 parent 6444311 commit b8a42e6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
43 changes: 37 additions & 6 deletions controllers/componentdetectionquery_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"time"

"github.com/go-logr/logr"
"github.com/hashicorp/go-multierror"
"github.com/prometheus/client_golang/prometheus"
appstudiov1alpha1 "github.com/redhat-appstudio/application-api/api/v1alpha1"
cdqanalysis "github.com/redhat-appstudio/application-service/cdq-analysis/pkg"
Expand Down Expand Up @@ -172,6 +173,8 @@ func (r *ComponentDetectionQueryReconciler) Reconcile(ctx context.Context, req c
var componentPortsMapReturned map[string][]int
revision := source.Revision

// with annotation runCDQAnalysisLocal = true, would allow the CDQ controller to run the cdq-analysis go modoule
// it is being used for CDQ controller tests to test both k8s job and go module
if r.RunKubernetesJob && !(componentDetectionQuery.Annotations["runCDQAnalysisLocal"] == "true") {
// perfume cdq job that requires repo cloning and azlier analysis
clientset, err := kubernetes.NewForConfig(r.Config)
Expand Down Expand Up @@ -256,13 +259,41 @@ func (r *ComponentDetectionQueryReconciler) Reconcile(ctx context.Context, req c
return ctrl.Result{}, nil
}
var errMapReturned map[string]string
json.Unmarshal(cm.BinaryData["devfilesMap"], &devfilesMapReturned)
json.Unmarshal(cm.BinaryData["dockerfileContextMap"], &dockerfileContextMapReturned)
json.Unmarshal(cm.BinaryData["devfilesURLMap"], &devfilesURLMapReturned)
json.Unmarshal(cm.BinaryData["componentPortsMap"], &componentPortsMapReturned)
json.Unmarshal(cm.BinaryData["revision"], &revision)
json.Unmarshal(cm.BinaryData["errorMap"], &errMapReturned)
var unmarshalErr error
err = json.Unmarshal(cm.BinaryData["devfilesMap"], &devfilesMapReturned)
if err != nil {
unmarshalErr = multierror.Append(unmarshalErr, fmt.Errorf("unmarshal devfilesMap: %v", err))
}
err = json.Unmarshal(cm.BinaryData["dockerfileContextMap"], &dockerfileContextMapReturned)
if err != nil {
unmarshalErr = multierror.Append(unmarshalErr, fmt.Errorf("unmarshal dockerfileContextMap: %v", err))
}
err = json.Unmarshal(cm.BinaryData["devfilesURLMap"], &devfilesURLMapReturned)
if err != nil {
unmarshalErr = multierror.Append(unmarshalErr, fmt.Errorf("unmarshal devfilesURLMap: %v", err))
}
err = json.Unmarshal(cm.BinaryData["componentPortsMap"], &componentPortsMapReturned)
if err != nil {
unmarshalErr = multierror.Append(unmarshalErr, fmt.Errorf("unmarshal componentPortsMap: %v", err))
}
err = json.Unmarshal(cm.BinaryData["revision"], &revision)
if err != nil {
unmarshalErr = multierror.Append(unmarshalErr, fmt.Errorf("unmarshal revision: %v", err))
}
err = json.Unmarshal(cm.BinaryData["errorMap"], &errMapReturned)
if err != nil {
unmarshalErr = multierror.Append(unmarshalErr, fmt.Errorf("unmarshal errorMap: %v", err))
}
cleanupK8sResources(log, clientset, ctx, fmt.Sprintf("%s-job", req.Name), req.Name, req.Namespace)

if unmarshalErr != nil {
// if a direct devfileURL is provided and errors out, we dont do an alizer detection
log.Error(unmarshalErr, fmt.Sprintf("Failed to unmarshal the returned result from CDQ configmap... %v", req.NamespacedName))
err := fmt.Errorf("Failed to unmarshal the returned result from CDQ configmap... ")
r.SetCompleteConditionAndUpdateCR(ctx, req, &componentDetectionQuery, copiedCDQ, err)
return ctrl.Result{}, nil
}

if errMapReturned != nil && !reflect.DeepEqual(errMapReturned, map[string]string{}) {
var retErr error
// only 1 index in the error map
Expand Down
9 changes: 8 additions & 1 deletion controllers/start_test_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controllers
import (
"context"
"go/build"
"os"
"path/filepath"

spiapi "github.com/redhat-appstudio/service-provider-integration-operator/api/v1beta1"
Expand Down Expand Up @@ -94,6 +95,12 @@ func SetupTestEnv() (client.Client, *envtest.Environment, context.Context, conte

mockGhTokenClient := github.MockGitHubTokenClient{}

// Retrieve the option to specify a cdq-analysis image
cdqAnalysisImage := os.Getenv("CDQ_ANALYSIS_IMAGE")
if cdqAnalysisImage == "" {
cdqAnalysisImage = "quay.io/redhat-appstudio/cdq-analysis:next"
}

// To Do: Set up reconcilers for the other controllers
err = (&ApplicationReconciler{
Client: k8sManager.GetClient(),
Expand Down Expand Up @@ -124,7 +131,7 @@ func SetupTestEnv() (client.Client, *envtest.Environment, context.Context, conte
AppFS: ioutils.NewMemoryFilesystem(),
Config: cfg,
RunKubernetesJob: true,
CdqAnalysisImage: "quay.io/redhat-appstudio/cdq-analysis:next",
CdqAnalysisImage: cdqAnalysisImage,
}).SetupWithManager(ctx, k8sManager)
gomega.Expect(err).ToNot(gomega.HaveOccurred())

Expand Down

0 comments on commit b8a42e6

Please sign in to comment.