-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Peter Hunt <[email protected]>
- Loading branch information
1 parent
9e7cce0
commit b74e50a
Showing
3 changed files
with
134 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
control-plane-operator/hostedclusterconfigoperator/controllers/featuregate/controller.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package featuregate | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/blang/semver/v4" | ||
hypershiftv1beta1 "github.com/openshift/hypershift/api/hypershift/v1beta1" | ||
"github.com/openshift/hypershift/support/util" | ||
nodelib "github.com/openshift/library-go/pkg/apiserver/node" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
|
||
hypershiftv1beta1applyconfigurations "github.com/openshift/hypershift/client/applyconfiguration/hypershift/v1beta1" | ||
hypershiftclient "github.com/openshift/hypershift/client/clientset/clientset" | ||
) | ||
|
||
type minimumKubeletVersionReconciler struct { | ||
hcpName, hcpNamespace string | ||
client hypershiftclient.Interface | ||
lister client.Client | ||
|
||
guestClusterClient client.Client | ||
} | ||
|
||
func (r *minimumKubeletVersionReconciler) Reconcile(ctx context.Context, _ reconcile.Request) (reconcile.Result, error) { | ||
log := ctrl.LoggerFrom(ctx) | ||
log.Info("Reconciling") | ||
|
||
var hcp hypershiftv1beta1.HostedControlPlane | ||
if err := r.lister.Get(ctx, client.ObjectKey{ | ||
Namespace: r.hcpNamespace, | ||
Name: r.hcpName, | ||
}, &hcp); err != nil { | ||
return reconcile.Result{}, err | ||
} | ||
if isPaused, duration := util.IsReconciliationPaused(log, hcp.Spec.PausedUntil); isPaused { | ||
log.Info("Reconciliation paused", "pausedUntil", *hcp.Spec.PausedUntil) | ||
return ctrl.Result{ | ||
RequeueAfter: duration, | ||
}, nil | ||
} | ||
if hcp.ObjectMeta.DeletionTimestamp != nil { | ||
return reconcile.Result{}, nil | ||
} | ||
|
||
nodes := &corev1.NodeList{} | ||
if err := r.guestClusterClient.List(ctx, nodes); err != nil { | ||
return ctrl.Result{}, fmt.Errorf("failed to get Nodes: %w", err) | ||
} | ||
|
||
currentOldestKubelet := getOldestKubeletVersion(nodes.Items) | ||
if currentOldestKubelet == nil { | ||
// no valid nodes, leave the field unset | ||
return reconcile.Result{}, nil | ||
} | ||
|
||
cfg := hypershiftv1beta1applyconfigurations.HostedControlPlane(r.hcpName, r.hcpNamespace) | ||
cfg.Status = hypershiftv1beta1applyconfigurations.HostedControlPlaneStatus().WithOldestKubeletVersion(currentOldestKubelet.String()) | ||
_, err := r.client.HypershiftV1beta1().HostedControlPlanes(r.hcpNamespace).ApplyStatus(ctx, cfg, metav1.ApplyOptions{FieldManager: ControllerName}) | ||
return reconcile.Result{}, err | ||
} | ||
|
||
func getOldestKubeletVersion(nodes []corev1.Node) *semver.Version { | ||
var oldestVersion *semver.Version | ||
for _, node := range nodes { | ||
vStr := node.Status.NodeInfo.KubeletVersion | ||
v, err := nodelib.ParseKubeletVersion(vStr) | ||
if err != nil { | ||
continue | ||
} | ||
if oldestVersion == nil || v.LT(*oldestVersion) { | ||
oldestVersion = v | ||
} | ||
} | ||
return oldestVersion | ||
} |
41 changes: 41 additions & 0 deletions
41
control-plane-operator/hostedclusterconfigoperator/controllers/featuregate/setup.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package featuregate | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
hypershiftclient "github.com/openshift/hypershift/client/clientset/clientset" | ||
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/operator" | ||
featuregate "github.com/openshift/hypershift/hypershift-operator/featuregate" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/client-go/util/workqueue" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/controller" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
) | ||
|
||
const ControllerName = "featuregate" | ||
|
||
func Setup(ctx context.Context, opts *operator.HostedClusterConfigOperatorConfig) error { | ||
if !featuregate.Gates.Enabled(featuregate.MinimumKubeletVersion) { | ||
return nil | ||
} | ||
|
||
hypershiftClient, err := hypershiftclient.NewForConfig(opts.CPCluster.GetConfig()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return ctrl.NewControllerManagedBy(opts.Manager). | ||
Named(ControllerName). | ||
For(&corev1.Node{}). | ||
WithOptions(controller.Options{ | ||
RateLimiter: workqueue.NewTypedItemExponentialFailureRateLimiter[reconcile.Request](1*time.Second, 10*time.Second), | ||
}).Complete(&minimumKubeletVersionReconciler{ | ||
hcpName: opts.HCPName, | ||
hcpNamespace: opts.Namespace, | ||
client: hypershiftClient, | ||
lister: opts.CPCluster.GetClient(), | ||
guestClusterClient: opts.Manager.GetClient(), | ||
}) | ||
} |