Skip to content

Commit

Permalink
vcsim: create tags for failuredomain tests for govmomi
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Aug 27, 2024
1 parent f16bfd2 commit f5a3e43
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/infrastructure/vcsim/controllers/vcsim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ func (r *VCenterSimulatorReconciler) reconcileNormal(ctx context.Context, vCente
if err := createVMTemplates(ctx, vCenterSimulator); err != nil {
return err
}

if !r.SupervisorMode {
// Create and attach tags for failure domain tests.
if err := createGovmomiFailureDomainTags(vCenterSimulator); err != nil {
return err
}
}
}

if vCenterSimulator.Status.Thumbprint == "" {
Expand Down Expand Up @@ -256,6 +263,30 @@ func createVMTemplates(ctx context.Context, vCenterSimulator *vcsimv1.VCenterSim
return nil
}

func createGovmomiFailureDomainTags(vCenterSimulator *vcsimv1.VCenterSimulator) error {
govcURLArg := fmt.Sprintf("-u=https://%s:%s@%s/sdk", vCenterSimulator.Status.Username, vCenterSimulator.Status.Password, vCenterSimulator.Status.Host)

datacenterName := vcsimhelpers.DatacenterName(0)
computeClusterName := vcsimhelpers.ClusterName(0, 0)
commands := [][]string{
{"tags.category.create", govcURLArg, "-d", "Kubernetes region", "-t=Datacenter", "k8s-region"},
{"tags.category.create", govcURLArg, "-d", "Kubernetes zone", "k8s-zone"},
{"tags.create", govcURLArg, "-c", "k8s-region", datacenterName},
{"tags.create", govcURLArg, "-c", "k8s-zone", computeClusterName},
{"tags.attach", govcURLArg, "-c", "k8s-region", datacenterName, "/" + datacenterName},
{"tags.attach", govcURLArg, "-c", "k8s-zone", computeClusterName, "/" + datacenterName + "/host/" + computeClusterName},
}

for _, command := range commands {
exit := cli.Run(command)
if exit != 0 {
return fmt.Errorf("failed to run command: %s", strings.Join(command, " "))
}
}

return nil
}

func (r *VCenterSimulatorReconciler) reconcileDelete(ctx context.Context, vCenterSimulator *vcsimv1.VCenterSimulator) {
log := ctrl.LoggerFrom(ctx)
log.Info("Reconciling delete VCenter server")
Expand Down

0 comments on commit f5a3e43

Please sign in to comment.