Skip to content

Commit

Permalink
Merge pull request k0sproject#591 from makhov/fix-autopilot-updates
Browse files Browse the repository at this point in the history
Fix controllers discovery for the autopilot plan
  • Loading branch information
makhov authored May 27, 2024
2 parents 80a3410 + 9a888af commit 7a0094d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions internal/controller/controlplane/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package controlplane
import (
"context"
"fmt"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"strings"
"time"

"github.com/Masterminds/semver"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/collections"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -189,11 +190,16 @@ func (c *K0sController) markChildControlNodeToLeave(ctx context.Context, name st
return nil
}

func (c *K0sController) createAutopilotPlan(ctx context.Context, kcp *cpv1beta1.K0sControlPlane, clientset *kubernetes.Clientset) error {
func (c *K0sController) createAutopilotPlan(ctx context.Context, kcp *cpv1beta1.K0sControlPlane, cluster *clusterv1.Cluster, clientset *kubernetes.Clientset) error {
if clientset == nil {
return nil
}

machines, err := collections.GetFilteredMachinesForCluster(ctx, c, cluster, collections.ControlPlaneMachines(cluster.Name), collections.ActiveMachines)
if err != nil {
return fmt.Errorf("error getting control plane machines: %w", err)
}

amd64DownloadURL := `https://get.k0sproject.io/` + kcp.Spec.Version + `/k0s-` + kcp.Spec.Version + `-amd64`
arm64DownloadURL := `https://get.k0sproject.io/` + kcp.Spec.Version + `/k0s-` + kcp.Spec.Version + `-arm64`
armDownloadURL := `https://get.k0sproject.io/` + kcp.Spec.Version + `/k0s-` + kcp.Spec.Version + `-arm`
Expand Down Expand Up @@ -231,7 +237,9 @@ func (c *K0sController) createAutopilotPlan(ctx context.Context, kcp *cpv1beta1.
"targets": {
"controllers": {
"discovery": {
"selector": {}
"static": {
"nodes": ["` + strings.Join(machines.Names(), `","`) + `"]
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (c *K0sController) reconcileMachines(ctx context.Context, cluster *clusterv
return replicasToReport, fmt.Errorf("error getting cluster client set for machine update: %w", err)
}

err = c.createAutopilotPlan(ctx, kcp, kubeClient)
err = c.createAutopilotPlan(ctx, kcp, cluster, kubeClient)
if err != nil {
return replicasToReport, fmt.Errorf("error creating autopilot plan: %w", err)
}
Expand Down

0 comments on commit 7a0094d

Please sign in to comment.