diff --git a/crd/cidrallocationpool.yaml b/charts/k3k/crds/cidrallocationpool.yaml similarity index 100% rename from crd/cidrallocationpool.yaml rename to charts/k3k/crds/cidrallocationpool.yaml diff --git a/crd/cluster.yaml b/charts/k3k/crds/cluster.yaml similarity index 93% rename from crd/cluster.yaml rename to charts/k3k/crds/cluster.yaml index c61505e5..eb04ce66 100644 --- a/crd/cluster.yaml +++ b/charts/k3k/crds/cluster.yaml @@ -57,8 +57,12 @@ spec: status: type: object properties: + overrideClusterCIDR: + type: boolean clusterCIDR: type: string + overrideServiceCIDR: + type: boolean serviceCIDR: type: string clusterDNS: diff --git a/pkg/apis/k3k.io/v1alpha1/types.go b/pkg/apis/k3k.io/v1alpha1/types.go index 76e3707d..357b459f 100644 --- a/pkg/apis/k3k.io/v1alpha1/types.go +++ b/pkg/apis/k3k.io/v1alpha1/types.go @@ -55,9 +55,11 @@ type LoadBalancerConfig struct { } type ClusterStatus struct { - ClusterCIDR string `json:"clusterCIDR,omitempty"` - ServiceCIDR string `json:"serviceCIDR,omitempty"` - ClusterDNS string `json:"clusterDNS,omitempty"` + OverrideClusterCIDR bool `json:"overrideClusterCIDR"` + OverrideServiceCIDR bool `json:"overrideServiceCIDR"` + ClusterCIDR string `json:"clusterCIDR,omitempty"` + ServiceCIDR string `json:"serviceCIDR,omitempty"` + ClusterDNS string `json:"clusterDNS,omitempty"` } type Allocation struct { diff --git a/pkg/controller/cluster/controller.go b/pkg/controller/cluster/controller.go index 4ce98960..b0d45c98 100644 --- a/pkg/controller/cluster/controller.go +++ b/pkg/controller/cluster/controller.go @@ -147,9 +147,16 @@ func (c *ClusterReconciler) Reconcile(ctx context.Context, req reconcile.Request } if controllerutil.ContainsFinalizer(&cluster, clusterFinalizerName) { - // TODO: handle CIDR deletion - if err := c.releaseCIDR(ctx, cluster.Status.ClusterCIDR, cluster.Name); err != nil { - return reconcile.Result{}, err + if !cluster.Status.OverrideClusterCIDR { + if err := c.releaseCIDR(ctx, cluster.Status.ClusterCIDR, cluster.Name); err != nil { + return reconcile.Result{}, err + } + } + + if !cluster.Status.OverrideServiceCIDR { + if err := c.releaseCIDR(ctx, cluster.Status.ServiceCIDR, cluster.Name); err != nil { + return reconcile.Result{}, err + } } // remove our finalizer from the list and update it. @@ -169,22 +176,30 @@ func (c *ClusterReconciler) createCluster(ctx context.Context, cluster *v1alpha1 return util.WrapErr("failed to create ns", err) } - if cluster.Spec.ClusterCIDR == "" && cluster.Status.ClusterCIDR == "" { + klog.Info(cluster) + if cluster.Spec.ClusterCIDR == "" { clusterCIDR, err := c.nextCIDR(ctx, cidrAllocationClusterPoolName, cluster.Name) if err != nil { return err } cluster.Status.ClusterCIDR = clusterCIDR.String() + } else { + cluster.Status.OverrideClusterCIDR = true + cluster.Status.ClusterCIDR = cluster.Spec.ClusterCIDR } - if cluster.Spec.ServiceCIDR == "" && cluster.Status.ServiceCIDR == "" { + if cluster.Spec.ServiceCIDR == "" { serviceCIDR, err := c.nextCIDR(ctx, cidrAllocationServicePoolName, cluster.Name) if err != nil { return err } cluster.Status.ServiceCIDR = serviceCIDR.String() + } else { + cluster.Status.OverrideServiceCIDR = true + cluster.Status.ClusterCIDR = cluster.Spec.ClusterCIDR } + klog.Infof("creating cluster service") serviceIP, err := c.createClusterService(ctx, cluster) if err != nil { return util.WrapErr("failed to create cluster service", err)