Skip to content

Commit

Permalink
Add function to check for OCP IPv6 cluster network
Browse files Browse the repository at this point in the history
The RabbitMQ config differs for IPv6 so add a function to determine if
IPv6 is enabled on the OCP cluster network, similar to the FIPS mode check
  • Loading branch information
olliewalsh committed Jul 8, 2024
1 parent 6c8da3c commit 243de2c
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions modules/common/ocp/ocp.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package ocp

import (
"context"
"strings"

"github.com/openstack-k8s-operators/lib-common/modules/common/helper"

Expand All @@ -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
}
Expand All @@ -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
}

0 comments on commit 243de2c

Please sign in to comment.