Skip to content

Commit aa99a64

Browse files
authored
🌱 e2e: servicediscovery controller to have an ip to discover in tests (#3405)
* e2e: servicediscovery controller to have an ip to discover in tests * vcsim: increase default qps and burst * fix * fixup * fix
1 parent 60a9b12 commit aa99a64

File tree

7 files changed

+79
-10
lines changed

7 files changed

+79
-10
lines changed

‎controllers/vmware/servicediscovery_controller.go‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ import (
6262
const (
6363
clusterNotReadyRequeueTime = time.Minute * 2
6464

65-
supervisorLoadBalancerSvcNamespace = "kube-system"
66-
supervisorLoadBalancerSvcName = "kube-apiserver-lb-svc"
67-
supervisorAPIServerPort = 6443
65+
supervisorAPIServerPort = 6443
6866

6967
supervisorHeadlessSvcNamespace = "default"
7068
supervisorHeadlessSvcName = "supervisor"

‎controllers/vmware/servicediscovery_controller_suite_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ func newTestSupervisorLBServiceWithHostnameStatus() *corev1.Service {
177177
func newTestSupervisorLBService() *corev1.Service {
178178
return &corev1.Service{
179179
ObjectMeta: metav1.ObjectMeta{
180-
Name: supervisorLoadBalancerSvcName,
181-
Namespace: supervisorLoadBalancerSvcNamespace,
180+
Name: vmwarev1.SupervisorLoadBalancerSvcName,
181+
Namespace: vmwarev1.SupervisorLoadBalancerSvcNamespace,
182182
},
183183
Spec: corev1.ServiceSpec{
184184
Type: corev1.ServiceTypeLoadBalancer,

‎test/framework/vmoperator/vmoperator.go‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
ctrl "sigs.k8s.io/controller-runtime"
4444
"sigs.k8s.io/controller-runtime/pkg/client"
4545

46+
vmwarev1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/vmware/v1beta1"
4647
topologyv1 "sigs.k8s.io/cluster-api-provider-vsphere/internal/apis/topology/v1alpha1"
4748
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/session"
4849
vcsimv1 "sigs.k8s.io/cluster-api-provider-vsphere/test/infrastructure/vcsim/api/v1alpha1"
@@ -361,6 +362,63 @@ func ReconcileDependencies(ctx context.Context, c client.Client, dependenciesCon
361362
return retryError
362363
}
363364

365+
// Create the supervisor service in kube-system for the servicediscovery controller to discover and set an IP address
366+
// for the headless service. When using kind as management cluster, the cluster-info configmap in kube-public contains a
367+
// hostname instead of an IP address which does not work for the servicediscovery controller.
368+
supervisorAPIServerVIPService := &corev1.Service{
369+
ObjectMeta: metav1.ObjectMeta{
370+
Name: vmwarev1.SupervisorLoadBalancerSvcName,
371+
Namespace: vmwarev1.SupervisorLoadBalancerSvcNamespace,
372+
},
373+
Spec: corev1.ServiceSpec{
374+
Type: corev1.ServiceTypeLoadBalancer,
375+
Ports: []corev1.ServicePort{
376+
{
377+
Name: "kube-apiserver",
378+
Protocol: corev1.ProtocolTCP,
379+
Port: 6443,
380+
},
381+
},
382+
},
383+
}
384+
_ = wait.PollUntilContextTimeout(ctx, 250*time.Millisecond, 5*time.Second, true, func(ctx context.Context) (bool, error) {
385+
retryError = nil
386+
if err := c.Get(ctx, client.ObjectKeyFromObject(supervisorAPIServerVIPService), supervisorAPIServerVIPService); err != nil {
387+
if !apierrors.IsNotFound(err) {
388+
retryError = errors.Wrapf(err, "failed to get vm-operator service %s", klog.KObj(supervisorAPIServerVIPService))
389+
return false, nil
390+
}
391+
if err := c.Create(ctx, supervisorAPIServerVIPService); err != nil {
392+
retryError = errors.Wrapf(err, "failed to create vm-operator service %s", klog.KObj(supervisorAPIServerVIPService))
393+
return false, nil
394+
}
395+
log.Info("Created vm-operator service", "Service", klog.KObj(supervisorAPIServerVIPService))
396+
}
397+
return true, nil
398+
})
399+
if retryError != nil {
400+
return retryError
401+
}
402+
supervisorAPIServerVIPService.Status = corev1.ServiceStatus{
403+
LoadBalancer: corev1.LoadBalancerStatus{Ingress: []corev1.LoadBalancerIngress{
404+
// Note: this creates a unusable service. During test no application should try to reach out to this.
405+
// 192.0.2.2 is part of the link-local subnet 192.0.2.0/24 which is reserved for documentation and testing.
406+
{IP: "192.0.2.2"},
407+
}},
408+
}
409+
_ = wait.PollUntilContextTimeout(ctx, 250*time.Millisecond, 5*time.Second, true, func(ctx context.Context) (bool, error) {
410+
retryError = nil
411+
if err := c.Status().Update(ctx, supervisorAPIServerVIPService); err != nil {
412+
retryError = errors.Wrapf(err, "failed to update vm-operator service status %s", klog.KObj(supervisorAPIServerVIPService))
413+
return false, nil
414+
}
415+
log.Info("Updated vm-operator service status", "Service", klog.KObj(supervisorAPIServerVIPService))
416+
return true, nil
417+
})
418+
if retryError != nil {
419+
return retryError
420+
}
421+
364422
// Create VirtualMachineClass in K8s
365423
for _, vmc := range config.Spec.VirtualMachineClasses {
366424
vmClass := &vmoprv1.VirtualMachineClass{

‎test/infrastructure/vcsim/config/rbac/role.yaml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ rules:
2323
- get
2424
- list
2525
- watch
26+
- apiGroups:
27+
- ""
28+
resources:
29+
- services
30+
- services/status
31+
verbs:
32+
- create
33+
- get
34+
- list
35+
- patch
36+
- update
37+
- watch
2638
- apiGroups:
2739
- authentication.k8s.io
2840
resources:

‎test/infrastructure/vcsim/controllers/vmip_controller.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ func (r *vmIPReconciler) ReconcileIP(ctx context.Context) (ctrl.Result, error) {
112112
MacAddress: macAddress,
113113
Adapter: types.CustomizationIPSettings{
114114
Ip: &types.CustomizationFixedIp{
115-
IpAddress: "192.168.1.100",
115+
IpAddress: "192.0.2.100",
116116
},
117117
SubnetMask: "255.255.255.0",
118-
Gateway: []string{"192.168.1.1"},
119-
DnsServerList: []string{"192.168.1.1"},
118+
Gateway: []string{"192.0.2.1"},
119+
DnsServerList: []string{"192.0.2.1"},
120120
DnsDomain: "ad.domain",
121121
},
122122
},

‎test/infrastructure/vcsim/controllers/vmoperatordependencies_controller.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type VMOperatorDependenciesReconciler struct {
4141

4242
// +kubebuilder:rbac:groups=vcsim.infrastructure.cluster.x-k8s.io,resources=vmoperatordependencies,verbs=get;list;watch;patch
4343
// +kubebuilder:rbac:groups=vcsim.infrastructure.cluster.x-k8s.io,resources=vmoperatordependencies/status,verbs=get;update;patch
44+
// +kubebuilder:rbac:groups="",resources=services;services/status,verbs=get;list;watch;create;update;patch
4445

4546
func (r *VMOperatorDependenciesReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
4647
// Fetch the VMOperatorDependencies instance

‎test/infrastructure/vcsim/main.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ func InitFlags(fs *pflag.FlagSet) {
159159
fs.DurationVar(&syncPeriod, "sync-period", 10*time.Minute,
160160
"The minimum interval at which watched resources are reconciled (e.g. 15m)")
161161

162-
fs.Float32Var(&restConfigQPS, "kube-api-qps", 20,
162+
fs.Float32Var(&restConfigQPS, "kube-api-qps", 100,
163163
"Maximum queries per second from the controller client to the Kubernetes API server.")
164164

165-
fs.IntVar(&restConfigBurst, "kube-api-burst", 30,
165+
fs.IntVar(&restConfigBurst, "kube-api-burst", 200,
166166
"Maximum number of queries that should be allowed in one burst from the controller client to the Kubernetes API server.")
167167

168168
fs.StringVar(&healthAddr, "health-addr", ":9440",

0 commit comments

Comments
 (0)