Skip to content

Commit

Permalink
Merge pull request #773 from cprivitere/emlb-templates
Browse files Browse the repository at this point in the history
✨ Add EMLB based templates for testing and deployment
  • Loading branch information
cprivitere committed Jun 25, 2024
2 parents 6d5a0ba + a731c31 commit b280f96
Show file tree
Hide file tree
Showing 14 changed files with 562 additions and 163 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ e2e-test-templates-v1beta1: $(KUSTOMIZE) ## Generate cluster templates for v1bet
mkdir -p $(TEST_TEMPLATES_TARGET_DIR)/v1beta1/
$(KUSTOMIZE) build $(REPO_ROOT)/templates/experimental-crs-cni --load-restrictor LoadRestrictionsNone > $(TEST_TEMPLATES_TARGET_DIR)/v1beta1/cluster-template.yaml
$(KUSTOMIZE) build $(REPO_ROOT)/templates/experimental-kube-vip-crs-cni --load-restrictor LoadRestrictionsNone > $(TEST_TEMPLATES_TARGET_DIR)/v1beta1/cluster-template-kube-vip.yaml
$(KUSTOMIZE) build $(REPO_ROOT)/templates/experimental-emlb-crs-cni --load-restrictor LoadRestrictionsNone > $(TEST_TEMPLATES_TARGET_DIR)/v1beta1/cluster-template-emlb.yaml
$(KUSTOMIZE) build $(REPO_ROOT)/test/e2e/data/v1beta1/cluster-template-kcp-scale-in --load-restrictor LoadRestrictionsNone > $(TEST_TEMPLATES_TARGET_DIR)/v1beta1/cluster-template-kcp-scale-in.yaml
$(KUSTOMIZE) build $(REPO_ROOT)/test/e2e/data/v1beta1/cluster-template-node-drain --load-restrictor LoadRestrictionsNone > $(TEST_TEMPLATES_TARGET_DIR)/v1beta1/cluster-template-node-drain.yaml
$(KUSTOMIZE) build $(REPO_ROOT)/test/e2e/data/v1beta1/cluster-template-md-remediation --load-restrictor LoadRestrictionsNone > $(TEST_TEMPLATES_TARGET_DIR)/v1beta1/cluster-template-md-remediation.yaml
Expand Down Expand Up @@ -282,6 +283,8 @@ generate: ## Generate code

.PHONY: generate-templates
generate-templates: $(KUSTOMIZE) ## Generate cluster templates
$(KUSTOMIZE) build templates/experimental-emlb --load-restrictor LoadRestrictionsNone > templates/cluster-template-emlb.yaml
$(KUSTOMIZE) build templates/experimental-emlb-crs-cni --load-restrictor LoadRestrictionsNone > templates/cluster-template-emlb-crs-cni.yaml
$(KUSTOMIZE) build templates/experimental-kube-vip-crs-cni --load-restrictor LoadRestrictionsNone > templates/cluster-template-kube-vip-crs-cni.yaml
$(KUSTOMIZE) build templates/experimental-kube-vip --load-restrictor LoadRestrictionsNone > templates/cluster-template-kube-vip.yaml
$(KUSTOMIZE) build templates/experimental-crs-cni --load-restrictor LoadRestrictionsNone > templates/cluster-template-crs-cni.yaml
Expand Down
6 changes: 6 additions & 0 deletions api/v1beta1/packetcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ const (
ClusterFinalizer = "packetcluster.infrastructure.cluster.x-k8s.io"
// NetworkInfrastructureReadyCondition reports of current status of cluster infrastructure.
NetworkInfrastructureReadyCondition clusterv1.ConditionType = "NetworkInfrastructureReady"
// EMLBVIPID is the string used to refer to the EMLB load balancer and VIP Manager type.
EMLBVIPID = "EMLB"
// CPEMID is the string used to refer to the CPEM load balancer and VIP Manager type.
CPEMID = "CPEM"
// KUBEVIPID is the string used to refer to the Kube VIP load balancer and VIP Manager type.
KUBEVIPID = "KUBE_VIP"
)

// VIPManagerType describes if the VIP will be managed by CPEM or kube-vip or Equinix Metal Load Balancer.
Expand Down
8 changes: 4 additions & 4 deletions controllers/packetcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (r *PacketClusterReconciler) reconcileNormal(ctx context.Context, clusterSc
packetCluster := clusterScope.PacketCluster

switch {
case packetCluster.Spec.VIPManager == emlb.EMLBVIPID:
case packetCluster.Spec.VIPManager == infrav1.EMLBVIPID:
if !packetCluster.Spec.ControlPlaneEndpoint.IsValid() {
// Create new EMLB object
lb := emlb.NewEMLB(r.PacketClient.GetConfig().DefaultHeader["X-Auth-Token"], packetCluster.Spec.ProjectID, packetCluster.Spec.Metro)
Expand All @@ -135,15 +135,15 @@ func (r *PacketClusterReconciler) reconcileNormal(ctx context.Context, clusterSc
return err
}
}
case packetCluster.Spec.VIPManager == "KUBE_VIP":
case packetCluster.Spec.VIPManager == infrav1.KUBEVIPID:
log.Info("KUBE_VIP VIPManager Detected")
if err := r.PacketClient.EnableProjectBGP(ctx, packetCluster.Spec.ProjectID); err != nil {
log.Error(err, "error enabling bgp for project")
return err
}
}

if packetCluster.Spec.VIPManager != emlb.EMLBVIPID {
if packetCluster.Spec.VIPManager != infrav1.EMLBVIPID {
ipReserv, err := r.PacketClient.GetIPByClusterIdentifier(ctx, clusterScope.Namespace(), clusterScope.Name(), packetCluster.Spec.ProjectID)
switch {
case errors.Is(err, packet.ErrControlPlanEndpointNotFound):
Expand Down Expand Up @@ -192,7 +192,7 @@ func (r *PacketClusterReconciler) reconcileDelete(ctx context.Context, clusterSc

packetCluster := clusterScope.PacketCluster

if packetCluster.Spec.VIPManager == emlb.EMLBVIPID {
if packetCluster.Spec.VIPManager == infrav1.EMLBVIPID {
// Create new EMLB object
lb := emlb.NewEMLB(r.PacketClient.GetConfig().DefaultHeader["X-Auth-Token"], packetCluster.Spec.ProjectID, packetCluster.Spec.Metro)

Expand Down
24 changes: 13 additions & 11 deletions controllers/packetmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
var controlPlaneEndpointAddress string
var cpemLBConfig string
var emlbID string
switch {
case machineScope.PacketCluster.Spec.VIPManager == "CPEM":
switch machineScope.PacketCluster.Spec.VIPManager {
case infrav1.CPEMID, infrav1.KUBEVIPID:
controlPlaneEndpoint, _ = r.PacketClient.GetIPByClusterIdentifier(
ctx,
machineScope.Cluster.Namespace,
Expand All @@ -368,7 +368,7 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
addrs = append(addrs, a)
}
controlPlaneEndpointAddress = controlPlaneEndpoint.GetAddress()
case machineScope.PacketCluster.Spec.VIPManager == emlb.EMLBVIPID:
case infrav1.EMLBVIPID:
controlPlaneEndpointAddress = machineScope.Cluster.Spec.ControlPlaneEndpoint.Host
cpemLBConfig = "emlb:///" + machineScope.PacketCluster.Spec.Metro
emlbID = machineScope.PacketCluster.Annotations["equinix.com/loadbalancerID"]
Expand Down Expand Up @@ -404,7 +404,7 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
machineScope.SetProviderID(dev.GetId())
machineScope.SetInstanceStatus(infrav1.PacketResourceStatus(dev.GetState()))

if machineScope.PacketCluster.Spec.VIPManager == "KUBE_VIP" {
if machineScope.PacketCluster.Spec.VIPManager == infrav1.KUBEVIPID {
if err := r.PacketClient.EnsureNodeBGPEnabled(ctx, dev.GetId()); err != nil {
// Do not treat an error enabling bgp on machine as fatal
return ctrl.Result{RequeueAfter: time.Second * 20}, fmt.Errorf("failed to enable bgp on machine %s: %w", machineScope.Name(), err)
Expand All @@ -426,7 +426,7 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
log.Info("Machine instance is active", "instance-id", machineScope.ProviderID())

switch {
case machineScope.PacketCluster.Spec.VIPManager == "CPEM":
case machineScope.PacketCluster.Spec.VIPManager == infrav1.CPEMID:
controlPlaneEndpoint, _ = r.PacketClient.GetIPByClusterIdentifier(
ctx,
machineScope.Cluster.Namespace,
Expand All @@ -441,7 +441,7 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
return ctrl.Result{RequeueAfter: time.Second * 20}, nil
}
}
case machineScope.PacketCluster.Spec.VIPManager == emlb.EMLBVIPID:
case machineScope.PacketCluster.Spec.VIPManager == infrav1.EMLBVIPID:
if machineScope.IsControlPlane() {
// Create new EMLB object
lb := emlb.NewEMLB(r.PacketClient.GetConfig().DefaultHeader["X-Auth-Token"], machineScope.PacketCluster.Spec.ProjectID, machineScope.PacketCluster.Spec.Metro)
Expand Down Expand Up @@ -543,12 +543,14 @@ func (r *PacketMachineReconciler) reconcileDelete(ctx context.Context, machineSc
return fmt.Errorf("%w: %s", errMissingDevice, packetmachine.Name)
}

if machineScope.PacketCluster.Spec.VIPManager == emlb.EMLBVIPID {
// Create new EMLB object
lb := emlb.NewEMLB(r.PacketClient.GetConfig().DefaultHeader["X-Auth-Token"], machineScope.PacketCluster.Spec.ProjectID, packetmachine.Spec.Metro)
if machineScope.PacketCluster.Spec.VIPManager == infrav1.EMLBVIPID {
if machineScope.IsControlPlane() {
// Create new EMLB object
lb := emlb.NewEMLB(r.PacketClient.GetConfig().DefaultHeader["X-Auth-Token"], machineScope.PacketCluster.Spec.ProjectID, packetmachine.Spec.Metro)

if err := lb.DeleteLoadBalancerOrigin(ctx, machineScope); err != nil {
return fmt.Errorf("failed to delete load balancer origin: %w", err)
if err := lb.DeleteLoadBalancerOrigin(ctx, machineScope); err != nil {
return fmt.Errorf("failed to delete load balancer origin: %w", err)
}
}
}

Expand Down
20 changes: 17 additions & 3 deletions docs/experiences/flavors.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,29 @@

### API Server VIP Management Choice

By default CPEM will be used to manage the EIP that serves as the VIP for the api-server. As of v0.6.0 you can choose to use kube-vip to manage the api-server VIP instead of CPEM.
By default CPEM will be used to manage the EIP that serves as the VIP for the api-server. Other flavors include kube-vip and Equinix Metal Load Balancer.

### Choosing Equinix Metal Load Balancer

To use Equinix Metal Load Balancer, when generating the template with `clusterctl`, pass in the `--flavor emlb` flag. For example, your `clusterctl generate` command might look like the following:

```sh
clusterctl generate cluster capi-quickstart \
--kubernetes-version v1.31.0 \
--control-plane-machine-count=3 \
--worker-machine-count=3 \
--infrastructure packet \
--flavor emlb
> capi-quickstart.yaml
```

### Choosing Kube-VIP

To use kube-vip, when generating the template with `clusterctl`, pass in the `--flavor kube-vip` flag. For example, your `clusterctl generate` command might look like the following:
To use kube-vip, when generating the template with `clusterctl`, pass in the `--flavor kube-vip` flag. For example, your `clusterctl generate` command might look like the following:

```sh
clusterctl generate cluster capi-quickstart \
--kubernetes-version v1.24.0 \
--kubernetes-version v1.31.0 \
--control-plane-machine-count=3 \
--worker-machine-count=3 \
--infrastructure packet \
Expand Down
2 changes: 0 additions & 2 deletions internal/emlb/emlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ const (
loadBalancerPoolIDAnnotation = "equinix.com/loadbalancerpoolID"
// loadBalancerPoolOriginIDAnnotation is the anotation key representing the origin ID of a PacketMachine.
loadBalancerOriginIDAnnotation = "equinix.com/loadbalanceroriginID"
// EMLBVIPID is the stringused to refer to the EMLB load balancer and VIP Manager type.
EMLBVIPID = "EMLB"
// loadbalancerTokenExchangeURL is the default URL to use for Token Exchange to talk to the Equinix Metal Load Balancer API.
loadbalancerTokenExchnageURL = "https://iam.metalctrl.io/api-keys/exchange" //nolint:gosec
)
Expand Down
Loading

0 comments on commit b280f96

Please sign in to comment.