Skip to content

Commit

Permalink
[vSphere] Don't fail when tag is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Demichev committed Aug 5, 2020
1 parent 950912b commit b360e92
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/controller/vsphere/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit b360e92

Please sign in to comment.