Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ require (
github.com/openshift/custom-resource-status v1.1.2
github.com/openshift/generic-admission-server v1.14.1-0.20231020105858-8dcc3c9b298f
github.com/openshift/hive/apis v0.0.0-20220222213051-def9088fdb5a
github.com/openshift/image-customization-controller v0.0.0-20240129110832-60a3867d7f9e
github.com/openshift/image-customization-controller v0.0.0-20240307203510-394809633b6b
github.com/openshift/library-go v0.0.0-20231110170715-08d73a9c798b
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pelletier/go-toml v1.9.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1379,8 +1379,8 @@ github.com/openshift/generic-admission-server v1.14.1-0.20231020105858-8dcc3c9b2
github.com/openshift/generic-admission-server v1.14.1-0.20231020105858-8dcc3c9b298f/go.mod h1:/CLsleDcQ6AFTGKJe9VL3Y4rB9DqX3fQwQv47q2/ZJc=
github.com/openshift/hive/apis v0.0.0-20220222213051-def9088fdb5a h1:E+XPJs/aVvYsrlJzo2ED38ZTR2RTNUlFMmOaFAAdMZg=
github.com/openshift/hive/apis v0.0.0-20220222213051-def9088fdb5a/go.mod h1:E1bgquRiwfugdArdecPbpYIrAdve5kTzMaJb0+8jMXI=
github.com/openshift/image-customization-controller v0.0.0-20240129110832-60a3867d7f9e h1:x1j5gWm4PdTTXTmuX3S7VAmsnazbbMiefQyCLdyjH74=
github.com/openshift/image-customization-controller v0.0.0-20240129110832-60a3867d7f9e/go.mod h1:rTvO75VGcFhEuE2HgQe10OijcR9HBDNC+CnKei8p1HE=
github.com/openshift/image-customization-controller v0.0.0-20240307203510-394809633b6b h1:SDdbzE3oW2qs7AJj4DT5gk8HDkZYR8DTT1ZfyBhECZ8=
github.com/openshift/image-customization-controller v0.0.0-20240307203510-394809633b6b/go.mod h1:G9yHOogitMOA0R5UWFmFup00E6nik8Sns/tCYYBU7jE=
github.com/openshift/library-go v0.0.0-20191003152030-97c62d8a2901/go.mod h1:NBttNjZpWwup/nthuLbPAPSYC8Qyo+BBK5bCtFoyYjo=
github.com/openshift/library-go v0.0.0-20200831114015-2ab0c61c15de/go.mod h1:6vwp+YhYOIlj8MpkQKkebTTSn2TuYyvgiAFQ206jIEQ=
github.com/openshift/library-go v0.0.0-20231110170715-08d73a9c798b h1:BmunS/b02dKSwQ0H21+3EbXDfDr9t8UDlO54WxKkOts=
Expand Down
43 changes: 42 additions & 1 deletion internal/controller/controllers/bmo_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,32 @@ import (
"github.com/openshift/cluster-baremetal-operator/provisioning"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const MinimalVersionForConvergedFlow = "4.12.0-0.alpha"
const (
MinimalVersionForConvergedFlow = "4.12.0-0.alpha"
iccNamespace = "openshift-machine-api"
iccSecretName = "metal3-image-customization-config" // #nosec G101
ironicBaseURLKey = "IRONIC_BASE_URL"
ironicInspectorBaseURLKey = "IRONIC_INSPECTOR_BASE_URL"
ironicAgentImageKey = "IRONIC_AGENT_IMAGE"
)

//go:generate mockgen --build_flags=--mod=mod -package=controllers -destination=mock_bmo_utils.go . BMOUtils
type BMOUtils interface {
ConvergedFlowAvailable() bool
GetIronicIPs() ([]string, []string, error)
getICCConfig(ctx context.Context) (*ICCConfig, error)
}

type ICCConfig struct {
IronicBaseURL string
IronicInspectorBaseUrl string
IronicAgentImage string
}

type bmoUtils struct {
Expand Down Expand Up @@ -91,6 +106,32 @@ func (r *bmoUtils) GetIronicIPs() ([]string, []string, error) {
return ironicIPs, inspectorIPs, nil
}

func (r *bmoUtils) getICCConfig(ctx context.Context) (*ICCConfig, error) {
const configKeyNotFoundError string = "Failed to get '%s' key from secret %s in namespace %s"

secret := &corev1.Secret{}
namespacedName := types.NamespacedName{Name: iccSecretName, Namespace: iccNamespace}
if err := r.c.Get(ctx, namespacedName, secret); err != nil {
return nil, fmt.Errorf("Failed to get secret %s in namespace %s: %w", iccSecretName, iccNamespace, err)
}

ironicBaseURL, ok := secret.Data[ironicBaseURLKey]
if !ok {
return nil, fmt.Errorf(configKeyNotFoundError, ironicBaseURLKey, secret.Name, secret.Namespace)
}

ironicAgentImage, ok := secret.Data[ironicAgentImageKey]
if !ok {
return nil, fmt.Errorf(configKeyNotFoundError, ironicAgentImageKey, secret.Name, secret.Namespace)
}

return &ICCConfig{
IronicBaseURL: string(ironicBaseURL),
IronicInspectorBaseUrl: string(secret.Data[ironicInspectorBaseURLKey]),
IronicAgentImage: string(ironicAgentImage),
}, nil
}

func (r *bmoUtils) getProvisioningInfo() (*provisioning.ProvisioningInfo, error) {
// Fetch the Provisioning instance
instance := &metal3iov1alpha1.Provisioning{}
Expand Down
97 changes: 97 additions & 0 deletions internal/controller/controllers/bmo_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
v1 "github.com/openshift/api/config/v1"
"github.com/openshift/assisted-service/internal/common"
metal3iov1alpha1 "github.com/openshift/cluster-baremetal-operator/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
Expand Down Expand Up @@ -122,6 +123,102 @@ var _ = Describe("bmoUtils", func() {
})

})
Context("getICCConfig", func() {
It("success", func() {
bmoUtils := &bmoUtils{
c: c,
log: log,
kubeAPIEnabled: true,
}
ironicURLs := getUrlFromIP("10.10.10.11")
inspectorURLs := getUrlFromIP("10.10.10.10")
agentImage := "quay.io/some/agent:image"
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: iccSecretName,
Namespace: iccNamespace,
},
Data: map[string][]byte{
ironicBaseURLKey: []byte(ironicURLs),
ironicInspectorBaseURLKey: []byte(inspectorURLs),
ironicAgentImageKey: []byte(agentImage),
},
}
Expect(c.Create(context.Background(), secret)).To(BeNil())
iccConfig, err := bmoUtils.getICCConfig(context.Background())
Expect(err).Should(BeNil())
Expect(iccConfig.IronicBaseURL).Should(Equal(ironicURLs))
Expect(iccConfig.IronicInspectorBaseUrl).Should(Equal(inspectorURLs))
Expect(iccConfig.IronicAgentImage).Should(Equal(agentImage))
})

It("succeeds when only the inspector url is missing", func() {
bmoUtils := &bmoUtils{
c: c,
log: log,
kubeAPIEnabled: true,
}
ironicURLs := getUrlFromIP("10.10.10.11")
agentImage := "quay.io/some/agent:image"
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: iccSecretName,
Namespace: iccNamespace,
},
Data: map[string][]byte{
ironicBaseURLKey: []byte(ironicURLs),
ironicAgentImageKey: []byte(agentImage),
},
}
Expect(c.Create(context.Background(), secret)).To(BeNil())
iccConfig, err := bmoUtils.getICCConfig(context.Background())
Expect(err).Should(BeNil())
Expect(iccConfig.IronicBaseURL).Should(Equal(ironicURLs))
Expect(iccConfig.IronicAgentImage).Should(Equal(agentImage))
})

It("throws an error when secret is missing", func() {
bmoUtils := &bmoUtils{
c: c,
log: log,
kubeAPIEnabled: true,
}
_, err := bmoUtils.getICCConfig(context.Background())
Expect(err).Should(Not(BeNil()))
})

DescribeTable("throws an error when config is incomplete",
func(ironicURLs []byte, inspectorURLs []byte, agentImage []byte) {
bmoUtils := &bmoUtils{
c: c,
log: log,
kubeAPIEnabled: true,
}
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: iccSecretName,
Namespace: iccNamespace,
},
Data: map[string][]byte{},
}
if ironicURLs != nil {
secret.Data[ironicBaseURLKey] = ironicURLs
}
if inspectorURLs != nil {
secret.Data[ironicInspectorBaseURLKey] = inspectorURLs
}
if agentImage != nil {
secret.Data[ironicAgentImageKey] = agentImage
}

Expect(c.Create(context.Background(), secret)).To(BeNil())
_, err := bmoUtils.getICCConfig(context.Background())
Expect(err).Should(Not(BeNil()))
},
Entry("ironicURLs is missing", nil, []byte("some"), []byte("some")),
Entry("ironicAgentImage is missing", []byte("some"), []byte("some"), nil),
)
})
})

func CreateCBO(version string) *v1.ClusterOperator {
Expand Down
16 changes: 16 additions & 0 deletions internal/controller/controllers/mock_bmo_utils.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading