Skip to content

Commit 5fc89a9

Browse files
committed
Check baremetal.openshift.io/owned before managing metal3 deployment
As per openshift/enhancements#212 MAO should stand down from managing the metal3 deployment if cluster-baremetal-operator has claimed ownership by setting the baremetal.openshift.io annotation. This allows a smooth transition on upgrade of bare metal components to a new Second Level Operator (SLO) for this platform.
1 parent 008d912 commit 5fc89a9

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

pkg/operator/baremetal_pod.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
corev1 "k8s.io/api/core/v1"
1111
apierrors "k8s.io/apimachinery/pkg/api/errors"
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+
appsclientv1 "k8s.io/client-go/kubernetes/typed/apps/v1"
1314
coreclientv1 "k8s.io/client-go/kubernetes/typed/core/v1"
1415
"k8s.io/utils/pointer"
1516
)
@@ -113,6 +114,21 @@ func createMariadbPasswordSecret(client coreclientv1.SecretsGetter, config *Oper
113114
return err
114115
}
115116

117+
// Return false on error or if "baremetal.openshift.io/owned" annotation set
118+
func checkMetal3DeploymentOwned(client appsclientv1.DeploymentsGetter, config *OperatorConfig) (bool, error) {
119+
existing, err := client.Deployments(config.TargetNamespace).Get(context.Background(), "metal3", metav1.GetOptions{})
120+
if err != nil {
121+
if apierrors.IsNotFound(err) {
122+
return true, nil
123+
}
124+
return false, err
125+
}
126+
if _, exists := existing.ObjectMeta.Annotations[cboOwnedAnnotation]; exists {
127+
return false, nil
128+
}
129+
return true, nil
130+
}
131+
116132
func newMetal3Deployment(config *OperatorConfig, baremetalProvisioningConfig BaremetalProvisioningConfig) *appsv1.Deployment {
117133
replicas := int32(1)
118134
template := newMetal3PodTemplateSpec(config, baremetalProvisioningConfig)

pkg/operator/operator.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const (
3232
// 5ms, 10ms, 20ms, 40ms, 80ms, 160ms, 320ms, 640ms, 1.3s, 2.6s, 5.1s, 10.2s, 20.4s, 41s, 82s
3333
maxRetries = 15
3434
maoOwnedAnnotation = "machine.openshift.io/owned"
35+
36+
// Indicates that the metal3 deployment is being managed by cluster-baremetal-operator
37+
cboOwnedAnnotation = "baremetal.openshift.io/owned"
3538
)
3639

3740
// Operator defines machine api operator.

pkg/operator/sync.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ func (optr *Operator) syncTerminationHandler(config *OperatorConfig) error {
117117
}
118118

119119
func (optr *Operator) syncBaremetalControllers(config *OperatorConfig) error {
120+
owned, err := checkMetal3DeploymentOwned(optr.kubeClient.AppsV1(), config)
121+
if err != nil {
122+
return err
123+
}
124+
if !owned {
125+
glog.Infof("cluster-baremetal-operator is managing the Metal3 deployment, standing down.")
126+
return nil
127+
}
128+
120129
// Try to get baremetal provisioning config from a CR
121130
baremetalProvisioningConfig, err := getBaremetalProvisioningConfig(optr.dynamicClient, baremetalProvisioningCR)
122131
if err != nil {

0 commit comments

Comments
 (0)