diff --git a/pkg/controller/vsphere/reconciler.go b/pkg/controller/vsphere/reconciler.go index 5a388b0450..61fb58a483 100644 --- a/pkg/controller/vsphere/reconciler.go +++ b/pkg/controller/vsphere/reconciler.go @@ -882,6 +882,16 @@ func (vm *virtualMachine) reconcileTags(ctx context.Context, session *session.Se // checkAttachedTag returns true if tag is already attached to a vm func (vm *virtualMachine) checkAttachedTag(ctx context.Context, tagName string, m *tags.Manager) (bool, error) { + // cluster ID tag doesn't exists in UPI, we should skip tag attachment if it's not found + foundTag, err := vm.foundTag(ctx, tagName, m) + if err != nil { + return false, err + } + + if !foundTag { + return true, nil + } + tags, err := m.GetAttachedTags(ctx, vm.Ref) if err != nil { return false, err @@ -896,6 +906,26 @@ func (vm *virtualMachine) checkAttachedTag(ctx context.Context, tagName string, return false, nil } +func (vm *virtualMachine) foundTag(ctx context.Context, tagName string, m *tags.Manager) (bool, error) { + tags, err := m.ListTags(ctx) + if err != nil { + return false, err + } + + for _, id := range tags { + tag, err := m.GetTag(ctx, id) + if err != nil { + return false, err + } + + if tag.Name == tagName { + return true, nil + } + } + + return false, nil +} + type NetworkStatus struct { // Connected is a flag that indicates whether this network is currently // connected to the VM.