Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions api/v1alpha3/packetcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
)

// VIPManagerType describes if the VIP will be managed by CPEM or kube-vip
type VIPManagerType string

// PacketClusterSpec defines the desired state of PacketCluster
type PacketClusterSpec struct {
// ProjectID represents the Packet Project where this cluster will be placed into
Expand All @@ -32,6 +35,12 @@ type PacketClusterSpec struct {
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
// +optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`

// VIPManager represents whether this cluster uses CPEM or kube-vip to
// manage its vip for the api server IP
// +kubebuilder:validation:Enum=CPEM;KUBE_VIP
// +kubebuilder:default:=CPEM
VIPManager VIPManagerType `json:"vipManager"`
}

// PacketClusterStatus defines the observed state of PacketCluster
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha3/zz_generated.conversion.go

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

9 changes: 9 additions & 0 deletions api/v1beta1/packetcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const (
NetworkInfrastructureReadyCondition clusterv1.ConditionType = "NetworkInfrastructureReady"
)

// VIPManagerType describes if the VIP will be managed by CPEM or kube-vip
type VIPManagerType string

// PacketClusterSpec defines the desired state of PacketCluster
type PacketClusterSpec struct {
// ProjectID represents the Packet Project where this cluster will be placed into
Expand All @@ -37,6 +40,12 @@ type PacketClusterSpec struct {
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
// +optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`

// VIPManager represents whether this cluster uses CPEM or kube-vip to
// manage its vip for the api server IP
// +kubebuilder:validation:Enum=CPEM;KUBE_VIP
// +kubebuilder:default:=CPEM
VIPManager VIPManagerType `json:"vipManager"`
}

// PacketClusterStatus defines the observed state of PacketCluster
Expand Down
7 changes: 7 additions & 0 deletions api/v1beta1/packetcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ func (c *PacketCluster) ValidateUpdate(oldRaw runtime.Object) error {
)
}

if !reflect.DeepEqual(c.Spec.VIPManager, old.Spec.VIPManager) {
allErrs = append(allErrs,
field.Invalid(field.NewPath("spec", "VIPManager"),
c.Spec.VIPManager, "field is immutable"),
)
}

if len(allErrs) == 0 {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,17 @@ spec:
description: ProjectID represents the Packet Project where this cluster
will be placed into
type: string
vipManager:
default: CPEM
description: VIPManager represents whether this cluster uses CPEM
or kube-vip to manage its vip for the api server IP
enum:
- CPEM
- KUBE_VIP
type: string
required:
- projectID
- vipManager
type: object
status:
description: PacketClusterStatus defines the observed state of PacketCluster
Expand Down Expand Up @@ -134,8 +143,17 @@ spec:
description: ProjectID represents the Packet Project where this cluster
will be placed into
type: string
vipManager:
default: CPEM
description: VIPManager represents whether this cluster uses CPEM
or kube-vip to manage its vip for the api server IP
enum:
- CPEM
- KUBE_VIP
type: string
required:
- projectID
- vipManager
type: object
status:
description: PacketClusterStatus defines the observed state of PacketCluster
Expand Down
7 changes: 0 additions & 7 deletions config/default/config.yaml

This file was deleted.

1 change: 0 additions & 1 deletion config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ commonLabels:

resources:
- namespace.yaml
- config.yaml
- credentials.yaml

bases:
Expand Down
2 changes: 0 additions & 2 deletions config/default/manager_credentials_config_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ spec:
envFrom:
- secretRef:
name: manager-api-credentials
- configMapRef:
name: manager-config
3 changes: 1 addition & 2 deletions controllers/packetcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"context"
"errors"
"os"

apierrors "k8s.io/apimachinery/pkg/api/errors"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -138,7 +137,7 @@ func (r *PacketClusterReconciler) reconcileNormal(ctx context.Context, clusterSc
}
}

if os.Getenv("EIP_MANAGEMENT") == "KUBE_VIP" {
if clusterScope.PacketCluster.Spec.VIPManager == "KUBE_VIP" {
if err := r.PacketClient.EnableProjectBGP(packetCluster.Spec.ProjectID); err != nil {
log.Error(err, "error enabling bgp for project")
return ctrl.Result{}, err
Expand Down
7 changes: 3 additions & 4 deletions controllers/packetmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"net/http"
"os"
"strings"
"time"

Expand Down Expand Up @@ -324,7 +323,7 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
machineScope.Cluster.Namespace,
machineScope.Cluster.Name,
machineScope.PacketCluster.Spec.ProjectID)
if os.Getenv("EIP_MANAGEMENT") == "CPEM" {
if machineScope.PacketCluster.Spec.VIPManager == "CPEM" {
if len(controlPlaneEndpoint.Assignments) == 0 {
a := corev1.NodeAddress{
Type: corev1.NodeExternalIP,
Expand Down Expand Up @@ -363,7 +362,7 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
machineScope.SetProviderID(dev.ID)
machineScope.SetInstanceStatus(infrav1.PacketResourceStatus(dev.State))

if os.Getenv("EIP_MANAGEMENT") == "KUBE_VIP" {
if machineScope.PacketCluster.Spec.VIPManager == "KUBE_VIP" {
if err := r.PacketClient.EnsureNodeBGPEnabled(dev.ID); 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 bpg on machine %s: %w", machineScope.Name(), err)
Expand All @@ -384,7 +383,7 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
case infrav1.PacketResourceStatusRunning:
log.Info("Machine instance is active", "instance-id", machineScope.GetInstanceID())

if os.Getenv("EIP_MANAGEMENT") == "CPEM" {
if machineScope.PacketCluster.Spec.VIPManager == "CPEM" {
controlPlaneEndpoint, _ = r.PacketClient.GetIPByClusterIdentifier(
machineScope.Cluster.Namespace,
machineScope.Cluster.Name,
Expand Down
1 change: 1 addition & 0 deletions templates/cluster-template-crs-cni.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ metadata:
spec:
facility: ${FACILITY}
projectID: ${PROJECT_ID}
vipManager: CPEM
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: PacketMachineTemplate
Expand Down
1 change: 1 addition & 0 deletions templates/cluster-template-kube-vip.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ metadata:
spec:
facility: ${FACILITY}
projectID: ${PROJECT_ID}
vipManager: KUBE_VIP
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: PacketMachineTemplate
Expand Down
1 change: 1 addition & 0 deletions templates/cluster-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ metadata:
spec:
projectID: "${PROJECT_ID}"
facility: "${FACILITY}"
vipManager: "CPEM"
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
Expand Down
7 changes: 7 additions & 0 deletions templates/experimental-kube-vip/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ patches:
cni: "${CLUSTER_NAME}-kube-vip"
target:
kind: Cluster
- patch: |-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: PacketCluster
metadata:
name: "${CLUSTER_NAME}"
spec:
vipManager: "KUBE_VIP"
- patch: |
kind: KubeadmControlPlane
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
Expand Down