Skip to content

Commit

Permalink
Add common/ocp module
Browse files Browse the repository at this point in the history
For FIPS support we need to be able to tell when an OCP cluster has been
deployed in FIPS mode (it's a day one operation).

This patch adds the `IsFipsCluster` function that checks if FIPS is
enabled or not.

The way to do that is checking the install-config YAML that is stored in
the cluster-config-v1 Config Map.

If we find the fips key, and it has the true value, then it's deployed
in FIPS mode, otherwise it isn't.
  • Loading branch information
Akrog committed Feb 6, 2024
1 parent c9467a8 commit 567e8ba
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/common/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/openstack-k8s-operators/lib-common/modules/common
go 1.19

require (
github.com/ghodss/yaml v1.0.0
github.com/go-logr/logr v1.4.1
github.com/google/uuid v1.5.0
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0
Expand Down
1 change: 1 addition & 0 deletions modules/common/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2Vvl
github.com/flowstack/go-jsonschema v0.1.1/go.mod h1:yL7fNggx1o8rm9RlgXv7hTBWxdBM0rVwpMwimd3F3N0=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down
49 changes: 49 additions & 0 deletions modules/common/ocp/ocp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright 2024 Red Hat
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package ocp

import (
"context"

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

"github.com/ghodss/yaml"
corev1 "k8s.io/api/core/v1"
"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) {
configMap := &corev1.ConfigMap{}
err := h.GetClient().Get(ctx, types.NamespacedName{Name: "cluster-config-v1", Namespace: "kube-system"}, configMap)
if err != nil {
return false, err
}

var installConfig map[string]interface{}
installConfigYAML := configMap.Data["install-config"]
err = yaml.Unmarshal([]byte(installConfigYAML), &installConfig)
if err != nil {
return false, err
}

fipsEnabled, ok := installConfig["fips"].(bool)
if !ok {
return false, nil
}
return fipsEnabled, nil
}

0 comments on commit 567e8ba

Please sign in to comment.