Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ set configured condition in mca #635

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
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ metadata:
categories: Integration & Delivery,OpenShift Optional
certified: "false"
containerImage: quay.io/open-cluster-management/registration-operator:latest
createdAt: "2024-07-14T00:10:06Z"
createdAt: "2024-10-08T08:24:18Z"
description: Manages the installation and upgrade of the ClusterManager.
operators.operatorframework.io/builder: operator-sdk-v1.32.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,39 @@ spec:
If it is set empty, use the default value: 50
format: int32
type: integer
registrationDriver:
description: This provides driver details required to register
with hub
properties:
authType:
default: csr
description: Type of the authentication used by managedcluster
to register as well as pull work from hub. Possible values
are csr and awsirsa.
enum:
- csr
- awsirsa
type: string
awsIrsa:
description: |-
Contain the details required for registering with hub cluster (ie: an EKS cluster) using AWS IAM roles for service account.
This is required only when the authType is awsirsa.
properties:
hubClusterArn:
description: |-
The arn of the hub cluster (ie: an EKS cluster). This will be required to pass information to hub, which hub will use to create IAM identities for this klusterlet.
Example - arn:eks:us-west-2:12345678910:cluster/hub-cluster1.
minLength: 1
type: string
managedClusterArn:
description: |-
The arn of the managed cluster (ie: an EKS cluster). This will be required to generate the md5hash which will be used as a suffix to create IAM role on hub
as well as used by kluslerlet-agent, to assume role suffixed with the md5hash, on startup.
Example - arn:eks:us-west-2:12345678910:cluster/managed-cluster1.
minLength: 1
type: string
type: object
type: object
type: object
registrationImagePullSpec:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,39 @@ spec:
If it is set empty, use the default value: 50
format: int32
type: integer
registrationDriver:
description: This provides driver details required to register
with hub
properties:
authType:
default: csr
description: Type of the authentication used by managedcluster
to register as well as pull work from hub. Possible values
are csr and awsirsa.
enum:
- csr
- awsirsa
type: string
awsIrsa:
description: |-
Contain the details required for registering with hub cluster (ie: an EKS cluster) using AWS IAM roles for service account.
This is required only when the authType is awsirsa.
properties:
hubClusterArn:
description: |-
The arn of the hub cluster (ie: an EKS cluster). This will be required to pass information to hub, which hub will use to create IAM identities for this klusterlet.
Example - arn:eks:us-west-2:12345678910:cluster/hub-cluster1.
minLength: 1
type: string
managedClusterArn:
description: |-
The arn of the managed cluster (ie: an EKS cluster). This will be required to generate the md5hash which will be used as a suffix to create IAM role on hub
as well as used by kluslerlet-agent, to assume role suffixed with the md5hash, on startup.
Example - arn:eks:us-west-2:12345678910:cluster/managed-cluster1.
minLength: 1
type: string
type: object
type: object
type: object
registrationImagePullSpec:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ metadata:
categories: Integration & Delivery,OpenShift Optional
certified: "false"
containerImage: quay.io/open-cluster-management/registration-operator:latest
createdAt: "2024-07-14T00:10:07Z"
createdAt: "2024-10-08T08:24:18Z"
description: Manages the installation and upgrade of the Klusterlet.
operators.operatorframework.io/builder: operator-sdk-v1.32.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,39 @@ spec:
If it is set empty, use the default value: 50
format: int32
type: integer
registrationDriver:
description: This provides driver details required to register
with hub
properties:
authType:
default: csr
description: Type of the authentication used by managedcluster
to register as well as pull work from hub. Possible values
are csr and awsirsa.
enum:
- csr
- awsirsa
type: string
awsIrsa:
description: |-
Contain the details required for registering with hub cluster (ie: an EKS cluster) using AWS IAM roles for service account.
This is required only when the authType is awsirsa.
properties:
hubClusterArn:
description: |-
The arn of the hub cluster (ie: an EKS cluster). This will be required to pass information to hub, which hub will use to create IAM identities for this klusterlet.
Example - arn:eks:us-west-2:12345678910:cluster/hub-cluster1.
minLength: 1
type: string
managedClusterArn:
description: |-
The arn of the managed cluster (ie: an EKS cluster). This will be required to generate the md5hash which will be used as a suffix to create IAM role on hub
as well as used by kluslerlet-agent, to assume role suffixed with the md5hash, on startup.
Example - arn:eks:us-west-2:12345678910:cluster/managed-cluster1.
minLength: 1
type: string
type: object
type: object
type: object
registrationImagePullSpec:
description: |-
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
k8s.io/kube-aggregator v0.30.3
k8s.io/utils v0.0.0-20240310230437-4693a0247e57
open-cluster-management.io/addon-framework v0.10.1-0.20240703130731-ba7fd000a03a
open-cluster-management.io/api v0.14.1-0.20240627145512-bd6f2229b53c
open-cluster-management.io/api v0.14.1-0.20241008081048-f6c658202790
open-cluster-management.io/sdk-go v0.14.1-0.20240918072645-225dcf1b6866
sigs.k8s.io/controller-runtime v0.18.5
sigs.k8s.io/kube-storage-version-migrator v0.0.6-0.20230721195810-5c8923c5ff96
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ k8s.io/utils v0.0.0-20240310230437-4693a0247e57 h1:gbqbevonBh57eILzModw6mrkbwM0g
k8s.io/utils v0.0.0-20240310230437-4693a0247e57/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
open-cluster-management.io/addon-framework v0.10.1-0.20240703130731-ba7fd000a03a h1:La1cYE3xkPFS2OJnsPQbkkahKE7yabuPcIISRfb4qsg=
open-cluster-management.io/addon-framework v0.10.1-0.20240703130731-ba7fd000a03a/go.mod h1:C1VETu/CIQKYfMiVAgNzPEUHjCpL9P1Z/KsGhHa4kl4=
open-cluster-management.io/api v0.14.1-0.20240627145512-bd6f2229b53c h1:gYfgkX/U6fv2d3Ly8D6N1GM9zokORupLSgCxx791zZw=
open-cluster-management.io/api v0.14.1-0.20240627145512-bd6f2229b53c/go.mod h1:9erZEWEn4bEqh0nIX2wA7f/s3KCuFycQdBrPrRzi0QM=
open-cluster-management.io/api v0.14.1-0.20241008081048-f6c658202790 h1:XszHWAR6PhYXBFPN4qgk8D5HVl8W/61j+bNMsXVuW7U=
open-cluster-management.io/api v0.14.1-0.20241008081048-f6c658202790/go.mod h1:9erZEWEn4bEqh0nIX2wA7f/s3KCuFycQdBrPrRzi0QM=
open-cluster-management.io/sdk-go v0.14.1-0.20240918072645-225dcf1b6866 h1:nxYrSsYwl9Mq8DuaJ0K98PCpuGsai+AvXbggMfZDCGI=
open-cluster-management.io/sdk-go v0.14.1-0.20240918072645-225dcf1b6866/go.mod h1:jCyXPY900UK1n4xwUBWSz27s7lcXN/fhIDF6xu3jIHw=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0 h1:/U5vjBbQn3RChhv7P11uhYvCSm5G2GaIi5AIGBS6r4c=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package addonconfiguration
import (
"context"

"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"

addonv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
addonv1alpha1client "open-cluster-management.io/api/client/addon/clientset/versioned"
Expand All @@ -19,13 +22,50 @@ type managedClusterAddonConfigurationReconciler struct {
func (d *managedClusterAddonConfigurationReconciler) reconcile(
ctx context.Context, cma *addonv1alpha1.ClusterManagementAddOn, graph *configurationGraph) (*addonv1alpha1.ClusterManagementAddOn, reconcileState, error) {
var errs []error
configured := sets.Set[string]{}

// Update the config references and set the "configured" condition to true for addons that are ready for rollout.
// These addons are part of the current rollout batch according to the strategy.
for _, addon := range graph.getAddonsToUpdate() {
mca := d.mergeAddonConfig(addon.mca, addon.desiredConfigs)
patcher := patcher.NewPatcher[
*addonv1alpha1.ManagedClusterAddOn, addonv1alpha1.ManagedClusterAddOnSpec, addonv1alpha1.ManagedClusterAddOnStatus](
d.addonClient.AddonV1alpha1().ManagedClusterAddOns(mca.Namespace))
_, err := patcher.PatchStatus(ctx, mca, mca.Status, addon.mca.Status)
// update mca config references in status
newAddon := d.mergeAddonConfig(addon.mca, addon.desiredConfigs)
// update mca configured condition to true
d.setCondition(newAddon, metav1.ConditionTrue, "ConfigurationsConfigured", "Configurations configured")

err := d.patchAddonStatus(ctx, newAddon, addon.mca)
if err != nil {
errs = append(errs, err)
}

configured.Insert(addon.mca.Namespace)
}

// Set the "configured" condition to false for addons whose configurations have not been synced yet
// but are waiting for rollout.
for _, addon := range graph.getAddonsToApply() {
// Skip addons that have already been configured.
if configured.Has(addon.mca.Namespace) {
continue
}
newAddon := addon.mca.DeepCopy()
d.setCondition(newAddon, metav1.ConditionFalse, "ConfigurationsNotConfigured", "Configurations updated and not configured yet")

err := d.patchAddonStatus(ctx, newAddon, addon.mca)
if err != nil {
errs = append(errs, err)
}
}

// Set the "configured" condition to true for addons that have successfully completed rollout.
// This includes:
// a. Addons without any configurations that have had their rollout status set to success in setRolloutStatus().
// b. Addons with configurations and already rollout successfully. In upgrade scenario, when the
// addon configurations do not change while addon components upgrade, should set condition to true.
for _, addon := range graph.getAddonsSucceeded() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not clear to me, should toUpdate and toApply include all addons need to be set? ToSuccess always comes from toUpdate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For addons that don't define any configs, the rollout status will be set to success insetRolloutStatus directly, and will never appear in the toUpdate or toApply.
Another case is for example, addon defines config A, and in next release, both addon-framework and addon-manager upgrades while it keeps using config A, since the desired config already matches the actual, will not have change to add configured condition in toUpdate or toApply.

newAddon := addon.mca.DeepCopy()
d.setCondition(newAddon, metav1.ConditionTrue, "ConfigurationsConfigured", "Configurations configured")

err := d.patchAddonStatus(ctx, newAddon, addon.mca)
if err != nil {
errs = append(errs, err)
}
Expand Down Expand Up @@ -88,3 +128,25 @@ func (d *managedClusterAddonConfigurationReconciler) mergeAddonConfig(
mcaCopy.Status.ConfigReferences = configRefs
return mcaCopy
}

// setCondition updates the configured condition for the addon
func (d *managedClusterAddonConfigurationReconciler) setCondition(
addon *addonv1alpha1.ManagedClusterAddOn, status metav1.ConditionStatus, reason, message string) {
meta.SetStatusCondition(&addon.Status.Conditions, metav1.Condition{
Type: addonv1alpha1.ManagedClusterAddOnConditionConfigured,
Status: status,
Reason: reason,
Message: message,
})
}

// patchAddonStatus patches the status of the addon
func (d *managedClusterAddonConfigurationReconciler) patchAddonStatus(
ctx context.Context, newaddon *addonv1alpha1.ManagedClusterAddOn, oldaddon *addonv1alpha1.ManagedClusterAddOn) error {
patcher := patcher.NewPatcher[
*addonv1alpha1.ManagedClusterAddOn, addonv1alpha1.ManagedClusterAddOnSpec, addonv1alpha1.ManagedClusterAddOnStatus](
d.addonClient.AddonV1alpha1().ManagedClusterAddOns(newaddon.Namespace))

_, err := patcher.PatchStatus(ctx, newaddon, newaddon.Status, oldaddon.Status)
return err
}
Loading
Loading