mirror of
https://github.com/rancher/k3k.git
synced 2026-08-19 04:16:16 +00:00
update per pr review
Signed-off-by: Brian Downs <brian.downs@gmail.com>
This commit is contained in:
@@ -60,7 +60,7 @@ func generateSubnets(cidr string) ([]string, error) {
|
||||
}
|
||||
|
||||
// nextCIDR retrieves the next available CIDR address from the given pool.
|
||||
func (c *ClusterReconciler) nextCIDR(ctx context.Context, namespace, cidrAllocationPoolName, clusterName string) (*net.IPNet, error) {
|
||||
func (c *ClusterReconciler) nextCIDR(ctx context.Context, cidrAllocationPoolName, clusterName string) (*net.IPNet, error) {
|
||||
var cidrPool v1alpha1.CIDRAllocationPool
|
||||
|
||||
nn := types.NamespacedName{
|
||||
@@ -95,7 +95,7 @@ func (c *ClusterReconciler) nextCIDR(ctx context.Context, namespace, cidrAllocat
|
||||
}
|
||||
|
||||
// releaseCIDR updates the given CIDR pool by marking the address as available.
|
||||
func (c *ClusterReconciler) releaseCIDR(ctx context.Context, namespace, cidrAllocationPoolName, clusterName string) error {
|
||||
func (c *ClusterReconciler) releaseCIDR(ctx context.Context, cidrAllocationPoolName, clusterName string) error {
|
||||
var cidrPool v1alpha1.CIDRAllocationPool
|
||||
|
||||
nn := types.NamespacedName{
|
||||
|
||||
@@ -145,18 +145,6 @@ func (c *ClusterReconciler) Reconcile(ctx context.Context, req reconcile.Request
|
||||
}
|
||||
}
|
||||
|
||||
clusterCIDR, err := c.nextCIDR(ctx, ns.String(), req.Name, cidrAllocationClusterPoolName)
|
||||
if err != nil {
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
cluster.Status.ClusterCIDR = clusterCIDR.String()
|
||||
|
||||
serviceCIDR, err := c.nextCIDR(ctx, ns.String(), req.Name, cidrAllocationServicePoolName)
|
||||
if err != nil {
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
cluster.Status.ServiceCIDR = serviceCIDR.String()
|
||||
|
||||
klog.Infof("enqueue cluster [%s]", cluster.Name)
|
||||
|
||||
return reconcile.Result{}, c.createCluster(ctx, &cluster)
|
||||
@@ -164,7 +152,7 @@ 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.Namespace, cluster.Status.ClusterCIDR, cluster.Name); err != nil {
|
||||
if err := c.releaseCIDR(ctx, cluster.Status.ClusterCIDR, cluster.Name); err != nil {
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
|
||||
@@ -185,6 +173,22 @@ func (c *ClusterReconciler) createCluster(ctx context.Context, cluster *v1alpha1
|
||||
return util.WrapErr("failed to create ns", err)
|
||||
}
|
||||
|
||||
if cluster.Spec.ClusterCIDR == "" && cluster.Status.ClusterCIDR == "" {
|
||||
clusterCIDR, err := c.nextCIDR(ctx, cidrAllocationClusterPoolName, cluster.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cluster.Status.ClusterCIDR = clusterCIDR.String()
|
||||
}
|
||||
|
||||
if cluster.Spec.ServiceCIDR == "" && cluster.Status.ServiceCIDR == "" {
|
||||
serviceCIDR, err := c.nextCIDR(ctx, cidrAllocationServicePoolName, cluster.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cluster.Status.ServiceCIDR = serviceCIDR.String()
|
||||
}
|
||||
|
||||
serviceIP, err := c.createClusterService(ctx, cluster)
|
||||
if err != nil {
|
||||
return util.WrapErr("failed to create cluster service", err)
|
||||
@@ -222,7 +226,7 @@ func (c *ClusterReconciler) createCluster(ctx context.Context, cluster *v1alpha1
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return c.Client.Update(ctx, cluster)
|
||||
}
|
||||
|
||||
func (c *ClusterReconciler) createNamespace(ctx context.Context, cluster *v1alpha1.Cluster) error {
|
||||
|
||||
Reference in New Issue
Block a user