diff --git a/modules/common/ocp/ocp.go b/modules/common/ocp/ocp.go index 6fb471d5..0cb22e17 100644 --- a/modules/common/ocp/ocp.go +++ b/modules/common/ocp/ocp.go @@ -18,6 +18,7 @@ package ocp import ( "context" + "strings" "github.com/openstack-k8s-operators/lib-common/modules/common/helper" @@ -26,17 +27,25 @@ import ( "k8s.io/apimachinery/pkg/types" ) -// IsFipsCluster - Check if OCP has fips enabled which is a day 1 operation -func IsFipsCluster(ctx context.Context, h *helper.Helper) (bool, error) { +func getInstallConfig(ctx context.Context, h *helper.Helper) (map[string]interface{}, error) { + var installConfig map[string]interface{} configMap := &corev1.ConfigMap{} err := h.GetClient().Get(ctx, types.NamespacedName{Name: "cluster-config-v1", Namespace: "kube-system"}, configMap) if err != nil { - return false, err + return installConfig, err } - var installConfig map[string]interface{} installConfigYAML := configMap.Data["install-config"] err = yaml.Unmarshal([]byte(installConfigYAML), &installConfig) + if err != nil { + return installConfig, err + } + return installConfig, nil +} + +// IsFipsCluster - Check if OCP has fips enabled which is a day 1 operation +func IsFipsCluster(ctx context.Context, h *helper.Helper) (bool, error) { + installConfig, err := getInstallConfig(ctx, h) if err != nil { return false, err } @@ -47,3 +56,29 @@ func IsFipsCluster(ctx context.Context, h *helper.Helper) (bool, error) { } return fipsEnabled, nil } + +// HasIPv6ClusterNetwork - Check if OCP has an IPv6 cluster network +func HasIPv6ClusterNetwork(ctx context.Context, h *helper.Helper) (bool, error) { + installConfig, err := getInstallConfig(ctx, h) + if err != nil { + return false, err + } + + networking, ok := installConfig["networking"].(map[string]interface{}) + if !ok { + return false, nil + } + clusterNetworks, ok := networking["clusterNetwork"].([]map[string]interface{}) + if !ok { + return false, nil + } + for _, clusterNetwork := range clusterNetworks { + cidr, ok := clusterNetwork["cidr"].(string) + if ok { + if strings.Count(cidr, ":") >= 2 { + return true, nil + } + } + } + return false, nil +}