From 1231b99e8fa5c592fd3647d4f0f546ef3cad4e85 Mon Sep 17 00:00:00 2001 From: Rokibul Hasan Date: Tue, 8 Oct 2024 14:05:20 +0600 Subject: [PATCH] Handle null pointer (#2) Signed-off-by: Rokibul Hasan --- pkg/feature_installer/helmrelease_create.go | 5 +++-- pkg/feature_installer/opscenter_features.go | 24 +++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/pkg/feature_installer/helmrelease_create.go b/pkg/feature_installer/helmrelease_create.go index 1cd575df..09c721b1 100644 --- a/pkg/feature_installer/helmrelease_create.go +++ b/pkg/feature_installer/helmrelease_create.go @@ -29,6 +29,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" cu "kmodules.xyz/client-go/client" uiapi "kmodules.xyz/resource-metadata/apis/ui/v1alpha1" + "kmodules.xyz/resource-metadata/hub" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -50,8 +51,8 @@ func createHR(featureName, featureSetName, ns string, profile *profilev1alpha1.M Version: profile.Spec.Features[featureName].Chart.Version, SourceRef: fluxhelm.CrossNamespaceObjectReference{ Kind: profile.Spec.Features[featureName].Chart.SourceRef.Kind, - Name: profile.Spec.Features[featureName].Chart.SourceRef.Name, - Namespace: profile.Spec.Features[featureName].Chart.SourceRef.Namespace, + Name: hub.BootstrapHelmRepositoryName(), + Namespace: hub.BootstrapHelmRepositoryNamespace(), }, }, }, diff --git a/pkg/feature_installer/opscenter_features.go b/pkg/feature_installer/opscenter_features.go index 89f06d9c..62bebb81 100644 --- a/pkg/feature_installer/opscenter_features.go +++ b/pkg/feature_installer/opscenter_features.go @@ -68,19 +68,21 @@ func InitializeServer(fakeServer *FakeServer, profile *profilev1alpha1.ManagedCl return nil, err } - if clusterMetadata.CAPI.Provider != "" { - if err := unstructured.SetNestedField(overrides, clusterMetadata.CAPI.Provider, "clusterMetadata", "capi", "provider"); err != nil { - return nil, err + if clusterMetadata.CAPI != nil { + if clusterMetadata.CAPI.Provider != "" { + if err := unstructured.SetNestedField(overrides, clusterMetadata.CAPI.Provider, "clusterMetadata", "capi", "provider"); err != nil { + return nil, err + } } - } - if clusterMetadata.CAPI.Namespace != "" { - if err := unstructured.SetNestedField(overrides, clusterMetadata.CAPI.Namespace, "clusterMetadata", "capi", "namespace"); err != nil { - return nil, err + if clusterMetadata.CAPI.Namespace != "" { + if err := unstructured.SetNestedField(overrides, clusterMetadata.CAPI.Namespace, "clusterMetadata", "capi", "namespace"); err != nil { + return nil, err + } } - } - if clusterMetadata.CAPI.ClusterName != "" { - if err := unstructured.SetNestedField(overrides, clusterMetadata.CAPI.Namespace, "clusterMetadata", "capi", "clusterName"); err != nil { - return nil, err + if clusterMetadata.CAPI.ClusterName != "" { + if err := unstructured.SetNestedField(overrides, clusterMetadata.CAPI.Namespace, "clusterMetadata", "capi", "clusterName"); err != nil { + return nil, err + } } } if len(clusterMetadata.ClusterManagers) > 0 {