Skip to content

Commit

Permalink
Fix vcsim API replacing int with int32
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed Feb 2, 2024
1 parent 187cd63 commit db3bdb5
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type ControlPlaneEndpointStatus struct {
Host string `json:"host,omitempty"`

// The control plane port.
Port int `json:"port,omitempty"`
Port int32 `json:"port,omitempty"`
}

// +kubebuilder:resource:path=controlplaneendpoints,scope=Namespaced,categories=cluster-api
Expand Down
10 changes: 5 additions & 5 deletions test/infrastructure/vcsim/api/v1alpha1/envvar_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ type ClusterEnvVarSpec struct {
// NOTE: This variable isn't related to the vcsim controller, but we are handling it here
// in order to have a single point of control for all the variables related to a Cluster API template.
// Default: 1
ControlPlaneMachines *int `json:"controlPlaneMachines,omitempty"`
ControlPlaneMachines *int32 `json:"controlPlaneMachines,omitempty"`

// The number of the worker machines in the Cluster API cluster.
// NOTE: This variable isn't related to the vcsim controller, but we are handling it here
// in order to have a single point of control for all the variables related to a Cluster API template.
// Default: 1
WorkerMachines *int `json:"workerMachines,omitempty"`
WorkerMachines *int32 `json:"workerMachines,omitempty"`

// Datacenter specifies the Datacenter for the Cluster API cluster.
// Default: 0 (DC0)
Datacenter *int `json:"datacenter,omitempty"`
Datacenter *int32 `json:"datacenter,omitempty"`

// Cluster specifies the VCenter Cluster for the Cluster API cluster.
// Default: 0 (C0)
Cluster *int `json:"cluster,omitempty"`
Cluster *int32 `json:"cluster,omitempty"`

// Datastore specifies the Datastore for the Cluster API cluster.
// Default: 0 (LocalDS_0)
Datastore *int `json:"datastore,omitempty"`
Datastore *int32 `json:"datastore,omitempty"`
}

// EnvVarStatus defines the observed state of the EnvVar.
Expand Down
10 changes: 5 additions & 5 deletions test/infrastructure/vcsim/api/v1alpha1/vcsim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ type VCenterSimulatorModel struct {
// Datacenter specifies the number of Datacenter entities to create
// Name prefix: DC, vcsim flag: -dc
// Default: 1
Datacenter *int `json:"datacenter,omitempty"`
Datacenter *int32 `json:"datacenter,omitempty"`

// Cluster specifies the number of ClusterComputeResource entities to create per Datacenter
// Name prefix: C, vcsim flag: -cluster
// Default: 1
Cluster *int `json:"cluster,omitempty"`
Cluster *int32 `json:"cluster,omitempty"`

// ClusterHost specifies the number of HostSystems entities to create within a Cluster
// Name prefix: H, vcsim flag: -host
// Default: 3
ClusterHost *int `json:"clusterHost,omitempty"`
ClusterHost *int32 `json:"clusterHost,omitempty"`

// Pool specifies the number of ResourcePool entities to create per Cluster
// Note that every cluster has a root ResourcePool named "Resources", as real vCenter does.
Expand All @@ -63,14 +63,14 @@ type VCenterSimulatorModel struct {
// Default: 0
// TODO: model pool selection for each cluster; for now ResourcePool named "Resources" will be always used
// but ideally we should use RPx as per documentation above.
Pool *int `json:"pool,omitempty"`
Pool *int32 `json:"pool,omitempty"`

// Datastore specifies the number of Datastore entities to create
// Each Datastore will have temporary local file storage and will be mounted
// on every HostSystem created by the ModelConfig
// Name prefix: LocalDS, vcsim flag: -ds
// Default: 1
Datastore *int `json:"datastore,omitempty"`
Datastore *int32 `json:"datastore,omitempty"`

// TODO: consider if to add options for creating more folders, networks, custom storage policies
}
Expand Down
20 changes: 10 additions & 10 deletions test/infrastructure/vcsim/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ spec:
type: string
port:
description: The control plane port.
format: int32
type: integer
type: object
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,25 @@ spec:
cluster:
description: 'Cluster specifies the VCenter Cluster for the Cluster
API cluster. Default: 0 (C0)'
format: int32
type: integer
controlPlaneMachines:
description: 'The number of the control plane machines in the
Cluster API cluster. NOTE: This variable isn''t related to the
vcsim controller, but we are handling it here in order to have
a single point of control for all the variables related to a
Cluster API template. Default: 1'
format: int32
type: integer
datacenter:
description: 'Datacenter specifies the Datacenter for the Cluster
API cluster. Default: 0 (DC0)'
format: int32
type: integer
datastore:
description: 'Datastore specifies the Datastore for the Cluster
API cluster. Default: 0 (LocalDS_0)'
format: int32
type: integer
kubernetesVersion:
description: 'The Kubernetes version of the Cluster API cluster.
Expand All @@ -75,6 +79,7 @@ spec:
controller, but we are handling it here in order to have a single
point of control for all the variables related to a Cluster
API template. Default: 1'
format: int32
type: integer
required:
- name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,25 @@ spec:
description: 'Cluster specifies the number of ClusterComputeResource
entities to create per Datacenter Name prefix: C, vcsim flag:
-cluster Default: 1'
format: int32
type: integer
clusterHost:
description: 'ClusterHost specifies the number of HostSystems
entities to create within a Cluster Name prefix: H, vcsim flag:
-host Default: 3'
format: int32
type: integer
datacenter:
description: 'Datacenter specifies the number of Datacenter entities
to create Name prefix: DC, vcsim flag: -dc Default: 1'
format: int32
type: integer
datastore:
description: 'Datastore specifies the number of Datastore entities
to create Each Datastore will have temporary local file storage
and will be mounted on every HostSystem created by the ModelConfig
Name prefix: LocalDS, vcsim flag: -ds Default: 1'
format: int32
type: integer
pool:
description: 'Pool specifies the number of ResourcePool entities
Expand All @@ -72,6 +76,7 @@ spec:
selection for each cluster; for now ResourcePool named "Resources"
will be always used but ideally we should use RPx as per documentation
above.'
format: int32
type: integer
vsphereVersion:
description: 'VSphereVersion specifies the VSphere version to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (r *ControlPlaneEndpointReconciler) reconcileNormal(ctx context.Context, co
r.InMemoryManager.AddResourceGroup(resourceGroup)

controlPlaneEndpoint.Status.Host = r.PodIP // NOTE: we are replacing the listener ip with the pod ip so it will be accessible from other pods as well
controlPlaneEndpoint.Status.Port = listener.Port()
controlPlaneEndpoint.Status.Port = int32(listener.Port())

return nil
}
Expand Down
11 changes: 6 additions & 5 deletions test/infrastructure/vcsim/controllers/envvar_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,19 @@ func (r *EnvVarReconciler) reconcileNormal(ctx context.Context, envVar *vcsimv1.
"NAMESPACE": vCenterSimulator.Namespace,
"CLUSTER_NAME": envVar.Spec.Cluster.Name,
"KUBERNETES_VERSION": ptr.Deref(envVar.Spec.Cluster.KubernetesVersion, "v1.28.0"),
"CONTROL_PLANE_MACHINE_COUNT": strconv.Itoa(ptr.Deref(envVar.Spec.Cluster.ControlPlaneMachines, 1)),
"WORKER_MACHINE_COUNT": strconv.Itoa(ptr.Deref(envVar.Spec.Cluster.WorkerMachines, 1)),
"CONTROL_PLANE_MACHINE_COUNT": strconv.Itoa(int(ptr.Deref(envVar.Spec.Cluster.ControlPlaneMachines, 1))),
"WORKER_MACHINE_COUNT": strconv.Itoa(int(ptr.Deref(envVar.Spec.Cluster.WorkerMachines, 1))),

// variables for the fake APIServer endpoint
"CONTROL_PLANE_ENDPOINT_IP": controlPlaneEndpoint.Status.Host,
"CONTROL_PLANE_ENDPOINT_PORT": strconv.Itoa(controlPlaneEndpoint.Status.Port),
"CONTROL_PLANE_ENDPOINT_PORT": strconv.Itoa(int(controlPlaneEndpoint.Status.Port)),

// variables to set up govc for working with the vcsim instance.
"GOVC_URL": fmt.Sprintf("https://%s:%s@%s/sdk", vCenterSimulator.Status.Username, vCenterSimulator.Status.Password, strings.Replace(vCenterSimulator.Status.Host, r.PodIP, "127.0.0.1", 1)), // NOTE: reverting back to local host because the assumption is that the vcsim pod will be port-forwarded on local host
"GOVC_INSECURE": "true",
}

// Variables below are generated using the same utilities used both also for E2E tests setup.
if r.SupervisorMode {
// Variables used only in supervisor mode
envVar.Status.Variables["VSPHERE_STORAGE_POLICY"] = "vcsim-default"
Expand All @@ -190,8 +191,8 @@ func (r *EnvVarReconciler) reconcileNormal(ctx context.Context, envVar *vcsimv1.
// cluster template variables about the vcsim instance.
envVar.Status.Variables["VSPHERE_SERVER"] = fmt.Sprintf("https://%s", vCenterSimulator.Status.Host)
envVar.Status.Variables["VSPHERE_TLS_THUMBPRINT"] = vCenterSimulator.Status.Thumbprint
envVar.Status.Variables["VSPHERE_DATACENTER"] = vcsimDatacenterName(ptr.Deref(envVar.Spec.Cluster.Datacenter, 0))
envVar.Status.Variables["VSPHERE_DATASTORE"] = vcsimDatastoreName(ptr.Deref(envVar.Spec.Cluster.Datastore, 0))
envVar.Status.Variables["VSPHERE_DATACENTER"] = vcsimDatacenterName(int(ptr.Deref(envVar.Spec.Cluster.Datacenter, 0)))
envVar.Status.Variables["VSPHERE_DATASTORE"] = vcsimDatastoreName(int(ptr.Deref(envVar.Spec.Cluster.Datastore, 0)))
envVar.Status.Variables["VSPHERE_FOLDER"] = fmt.Sprintf("/DC%d/vm", ptr.Deref(envVar.Spec.Cluster.Datacenter, 0))
envVar.Status.Variables["VSPHERE_NETWORK"] = fmt.Sprintf("/DC%d/network/VM Network", ptr.Deref(envVar.Spec.Cluster.Datacenter, 0))
envVar.Status.Variables["VSPHERE_RESOURCE_POOL"] = fmt.Sprintf("/DC%d/host/DC%[1]d_C%d/Resources", ptr.Deref(envVar.Spec.Cluster.Datacenter, 0), ptr.Deref(envVar.Spec.Cluster.Cluster, 0))
Expand Down
2 changes: 1 addition & 1 deletion test/infrastructure/vcsim/controllers/vcsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func createVMTemplate(ctx context.Context, vCenterSimulator *vcsimv1.VCenterSimu
datastore := 0
datacenters := 1
if vCenterSimulator.Spec.Model != nil {
datacenters = ptr.Deref(vCenterSimulator.Spec.Model.Datacenter, simulator.VPX().Datacenter) // VPX is the same base model used when creating vcsim
datacenters = int(ptr.Deref(vCenterSimulator.Spec.Model.Datacenter, int32(simulator.VPX().Datacenter))) // VPX is the same base model used when creating vcsim
}
for dc := 0; dc < datacenters; dc++ {
exit := cli.Run([]string{"vm.create", fmt.Sprintf("-ds=%s", vcsimDatastoreName(datastore)), fmt.Sprintf("-cluster=%s", vcsimClusterName(dc, cluster)), fmt.Sprintf("-net=%s", vcsimDefaultNetworkName), "-disk=20G", "-on=false", "-k=true", fmt.Sprintf("-u=%s", govcURL), vcsimDefaultVMTemplateName})
Expand Down
10 changes: 5 additions & 5 deletions test/infrastructure/vcsim/controllers/vcsim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ func (r *VCenterSimulatorReconciler) reconcileNormal(ctx context.Context, vCente
model.ServiceContent.About.Version = vcsimMinVersionForCAPV
if vCenterSimulator.Spec.Model != nil {
model.ServiceContent.About.Version = ptr.Deref(vCenterSimulator.Spec.Model.VSphereVersion, model.ServiceContent.About.Version)
model.Datacenter = ptr.Deref(vCenterSimulator.Spec.Model.Datacenter, model.Datacenter)
model.Cluster = ptr.Deref(vCenterSimulator.Spec.Model.Cluster, model.Cluster)
model.ClusterHost = ptr.Deref(vCenterSimulator.Spec.Model.ClusterHost, model.ClusterHost)
model.Pool = ptr.Deref(vCenterSimulator.Spec.Model.Pool, model.Pool)
model.Datastore = ptr.Deref(vCenterSimulator.Spec.Model.Datastore, model.Datastore)
model.Datacenter = int(ptr.Deref(vCenterSimulator.Spec.Model.Datacenter, int32(model.Datacenter)))
model.Cluster = int(ptr.Deref(vCenterSimulator.Spec.Model.Cluster, int32(model.Cluster)))
model.ClusterHost = int(ptr.Deref(vCenterSimulator.Spec.Model.ClusterHost, int32(model.ClusterHost)))
model.Pool = int(ptr.Deref(vCenterSimulator.Spec.Model.Pool, int32(model.Pool)))
model.Datastore = int(ptr.Deref(vCenterSimulator.Spec.Model.Datastore, int32(model.Datastore)))
}
if err := model.Create(); err != nil {
return errors.Wrapf(err, "failed to create vcsim server model")
Expand Down

0 comments on commit db3bdb5

Please sign in to comment.