diff --git a/install/autodetect.go b/install/autodetect.go index ea9890871d..2f66d59033 100644 --- a/install/autodetect.go +++ b/install/autodetect.go @@ -12,6 +12,7 @@ import ( "github.com/cilium/cilium-cli/k8s" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) type validationCheck interface { @@ -39,25 +40,13 @@ func (p Parameters) checkDisabled(name string) bool { return false } -func (k *K8sInstaller) detectDatapathMode() error { +func (k *K8sInstaller) detectDatapathMode(helmValues map[string]interface{}) error { if k.params.DatapathMode != "" { k.Log("ℹ️ Custom datapath mode: %s", k.params.DatapathMode) return nil } - vals, err := k.getHelmValues() - if err != nil { - return err - } - - routingMode := "" - for _, val := range vals { - val, ok := val.(string) - if ok && strings.HasPrefix(val, "routingMode") { - routingMode = strings.Split(val, "=")[1] - } - - } + routingMode, _, _ := unstructured.NestedString(helmValues, "routingMode") if routingMode == "native" { k.params.DatapathMode = DatapathNative return nil @@ -105,14 +94,7 @@ func (k *K8sInstaller) autodetect(ctx context.Context) { } func getClusterName(helmValues map[string]interface{}) string { - cluster, ok := helmValues["cluster"].(map[string]interface{}) - if !ok { - return "" - } - clusterName, ok := cluster["name"].(string) - if !ok { - return "" - } + clusterName, _, _ := unstructured.NestedString(helmValues, "cluster", "name") return clusterName } @@ -152,7 +134,7 @@ func (k *K8sInstaller) autodetectAndValidate(ctx context.Context, helmValues map k.Log("ℹ️ Using cluster name %q", k.params.ClusterName) } - if err := k.detectDatapathMode(); err != nil { + if err := k.detectDatapathMode(helmValues); err != nil { return err } diff --git a/install/azure.go b/install/azure.go index 37f07ff033..7f23c4ec03 100644 --- a/install/azure.go +++ b/install/azure.go @@ -9,6 +9,7 @@ import ( "helm.sh/helm/v3/pkg/cli" "helm.sh/helm/v3/pkg/getter" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) type accountInfo struct { @@ -83,14 +84,8 @@ func (k *K8sInstaller) setAzureResourceGroupFromHelmValue() error { if err != nil { return err } - azure, ok := values["azure"].(map[string]interface{}) - if !ok { - return nil - } - resourceGroupName, ok := azure["resourceGroup"].(string) - if !ok { - return nil - } + + resourceGroupName, _, _ := unstructured.NestedString(values, "azure", "resourceGroup") if resourceGroupName != "" { k.params.Azure.ResourceGroupName = resourceGroupName } diff --git a/install/install.go b/install/install.go index 34c069fbc5..a1f703100b 100644 --- a/install/install.go +++ b/install/install.go @@ -18,6 +18,7 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/yaml" @@ -176,14 +177,7 @@ func (k *K8sInstaller) listVersions() error { } func getChainingMode(values map[string]interface{}) string { - cni, ok := values["cni"].(map[string]interface{}) - if !ok { - return "" - } - chainingMode, ok := cni["chainingMode"].(string) - if !ok { - return "" - } + chainingMode, _, _ := unstructured.NestedString(values, "cni", "chainingMode") return chainingMode }