Skip to content

Commit

Permalink
Revert "test: ensure tags for failure domains on VCSim for govmomi"
Browse files Browse the repository at this point in the history
This reverts commit a7c3bfb.
  • Loading branch information
chrischdi committed Aug 27, 2024
1 parent 40673ae commit 5abc97d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 91 deletions.
87 changes: 0 additions & 87 deletions test/e2e/ownerrefs_finalizers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
"github.com/vmware/govmomi/find"
govmomirest "github.com/vmware/govmomi/vapi/rest"
govmomitags "github.com/vmware/govmomi/vapi/tags"
"github.com/vmware/govmomi/vim25/mo"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -87,11 +83,6 @@ var _ = Describe("Ensure OwnerReferences and Finalizers are resilient [vcsim] [s

// Before running the test create the secret used by the VSphereClusterIdentity to connect to the vCenter.
createVsphereIdentitySecret(ctx, bootstrapClusterProxy, username, password)

if testTarget == VCSimTestTarget {
// Create the necessary k8s-region and k8s-zone tags in VCSim for the failure domain.
createGovmomiFailureDomainTags(ctx, restClient, vsphereFinder, e2eConfig.GetVariable("VSPHERE_DATACENTER"), e2eConfig.GetVariable("VSPHERE_COMPUTE_CLUSTER"))
}
}
},
PostMachinesProvisioned: func(proxy framework.ClusterProxy, namespace, clusterName string) {
Expand Down Expand Up @@ -375,84 +366,6 @@ func createVsphereIdentitySecret(ctx context.Context, bootstrapClusterProxy fram
})).To(Succeed())
}

func ensureTagOnObject(ctx context.Context, tm *govmomitags.Manager, categoryName, tagName string, ref mo.Reference) error {
var categoryID string
var tagID string

// Create category if it does not exist.
categories, err := tm.GetCategories(ctx)
if err != nil {
return err
}

for _, category := range categories {
if category.Name == categoryName {
categoryID = category.ID
break
}
}

if categoryID == "" {
categoryID, err = tm.CreateCategory(ctx, &govmomitags.Category{Name: categoryName})
if err != nil {
return errors.Wrapf(err, "create category %q", categoryName)
}
}

// Create tag if it does not exist.
tags, err := tm.GetTagsForCategory(ctx, categoryID)
if err != nil {
return err
}

for _, tag := range tags {
if tag.Name == tagName {
tagID = tag.ID
break
}
}

if tagID == "" {
tagID, err = tm.CreateTag(ctx, &govmomitags.Tag{Name: tagName, CategoryID: categoryID})
if err != nil {
return errors.Wrapf(err, "create tag %q for category %q", tagName, categoryName)
}
}

// Ensure tag is set on object.
objTags, err := tm.GetAttachedTags(ctx, ref)
if err != nil {
return err
}

for _, objTag := range objTags {
if objTag.ID == tagID {
// Return early if tag is already attached to object.
return nil
}
}

return tm.AttachTag(ctx, tagID, ref)
}

func createGovmomiFailureDomainTags(ctx context.Context, restClient *govmomirest.Client, finder *find.Finder, datacenterName, computeClusterName string) {
// Get datacenter.
dc, err := finder.Datacenter(ctx, fmt.Sprintf("/%s", datacenterName))
Expect(err).ToNot(HaveOccurred())

// Get ComputeCluster.
computeCluster, err := finder.ClusterComputeResource(ctx, fmt.Sprintf("/%s/host/%s", datacenterName, computeClusterName))
Expect(err).ToNot(HaveOccurred())

m := govmomitags.NewManager(restClient)

// Ensure k8s-region tag on datacenter object.
Expect(ensureTagOnObject(ctx, m, "k8s-region", datacenterName, dc.Reference())).To(Succeed(), "ensure tag for k8s-region on datacenter")

// Ensure k8s-zone tag on computeCluster object.
Expect(ensureTagOnObject(ctx, m, "k8s-zone", computeClusterName, computeCluster.Reference())).To(Succeed(), "ensure tag for k8s-zone on cluster")
}

func checkGovmomiVSphereClusterFailureDomains(ctx context.Context, proxy framework.ClusterProxy, namespace, clusterName string) {
vSphereCluster := &infrav1.VSphereCluster{
ObjectMeta: metav1.ObjectMeta{
Expand Down
8 changes: 4 additions & 4 deletions test/infrastructure/vcsim/controllers/vcsim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ func (r *VCenterSimulatorReconciler) reconcileNormal(ctx context.Context, vCente
operations = append(operations,
"tags.category.create -d \"Kubernetes region\" -t Datacenter k8s-region",
"tags.category.create -d \"Kubernetes zone\" k8s-zone",
fmt.Sprintf("govc tags.create -c k8s-region %q", vcsimhelpers.DatacenterName(0)),
fmt.Sprintf("govc tags.create -c k8s-zone %q", vcsimhelpers.ClusterName(0, 0)),
fmt.Sprintf("govc tags.attach -c k8s-region %[1]q /%[1]q", vcsimhelpers.DatacenterName(0)),
fmt.Sprintf("govc tags.attach -c k8s-zone %[1]q /%[2]q/host/%[1]q", vcsimhelpers.ClusterName(0, 0), vcsimhelpers.DatacenterName(0)),
fmt.Sprintf("tags.create -c k8s-region %q", vcsimhelpers.DatacenterName(0)),
fmt.Sprintf("tags.create -c k8s-zone %q", vcsimhelpers.ClusterName(0, 0)),
fmt.Sprintf("tags.attach -c k8s-region %[1]q /%[1]q", vcsimhelpers.DatacenterName(0)),
fmt.Sprintf("tags.attach -c k8s-zone %[1]q /%[2]q/host/%[1]q", vcsimhelpers.ClusterName(0, 0), vcsimhelpers.DatacenterName(0)),
)
}

Expand Down

0 comments on commit 5abc97d

Please sign in to comment.