-
Notifications
You must be signed in to change notification settings - Fork 226
Set clusterID label on machine #608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,6 +22,7 @@ import ( | |||||||||||||||||||||||||||||||
"fmt" | ||||||||||||||||||||||||||||||||
"time" | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
configv1 "github.com/openshift/api/config/v1" | ||||||||||||||||||||||||||||||||
machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1" | ||||||||||||||||||||||||||||||||
"github.com/openshift/machine-api-operator/pkg/util" | ||||||||||||||||||||||||||||||||
corev1 "k8s.io/api/core/v1" | ||||||||||||||||||||||||||||||||
|
@@ -91,6 +92,8 @@ const ( | |||||||||||||||||||||||||||||||
unknownInstanceState = "Unknown" | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
skipWaitForDeleteTimeoutSeconds = 60 * 5 | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
globalInfrastuctureName = "cluster" | ||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
var DefaultActuator Actuator | ||||||||||||||||||||||||||||||||
|
@@ -175,6 +178,11 @@ func (r *ReconcileMachine) Reconcile(request reconcile.Request) (reconcile.Resul | |||||||||||||||||||||||||||||||
return reconcile.Result{}, err | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
// Add clusterID label | ||||||||||||||||||||||||||||||||
if err := r.setClusterIDLabel(ctx, m); err != nil { | ||||||||||||||||||||||||||||||||
return reconcile.Result{}, err | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
// If object hasn't been deleted and doesn't have a finalizer, add one | ||||||||||||||||||||||||||||||||
// Add a finalizer to newly created objects. | ||||||||||||||||||||||||||||||||
if m.ObjectMeta.DeletionTimestamp.IsZero() { | ||||||||||||||||||||||||||||||||
|
@@ -462,6 +470,25 @@ func (r *ReconcileMachine) patchFailedMachineInstanceAnnotation(machine *machine | |||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
func (r *ReconcileMachine) setClusterIDLabel(ctx context.Context, m *machinev1.Machine) error { | ||||||||||||||||||||||||||||||||
infra := &configv1.Infrastructure{} | ||||||||||||||||||||||||||||||||
infraName := client.ObjectKey{Name: globalInfrastuctureName} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
if err := r.Client.Get(ctx, infraName, infra); err != nil { | ||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
Comment on lines
+474
to
+479
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be substituted with machine-api-operator/pkg/controller/vsphere/util.go Lines 51 to 65 in 60eb822
With added tests from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't want to import a function from vsphere utils, but making a shared utils package in future makes sense. Anyway, it's not the scope of this PR |
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
clusterID := infra.Status.InfrastructureName | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
if m.Labels == nil { | ||||||||||||||||||||||||||||||||
m.Labels = make(map[string]string) | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
m.Labels[machinev1.MachineClusterIDLabel] = clusterID | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
func machineIsProvisioned(machine *machinev1.Machine) bool { | ||||||||||||||||||||||||||||||||
return len(machine.Status.Addresses) > 0 || stringPointerDeref(machine.Spec.ProviderID) != "" | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, VSphere util already exposes this variable:
machine-api-operator/pkg/controller/vsphere/util.go
Line 18 in 60eb822