diff --git a/pkg/cmds/manager/helpers.go b/pkg/cmds/manager/helpers.go new file mode 100644 index 00000000..be970cf1 --- /dev/null +++ b/pkg/cmds/manager/helpers.go @@ -0,0 +1,51 @@ +package manager + +import ( + "fmt" + + "github.com/kluster-manager/cluster-auth/pkg/common" + + agentapi "open-cluster-management.io/addon-framework/pkg/agent" + workapiv1 "open-cluster-management.io/api/work/v1" +) + +// agentHealthProber returns an instance of the agent's health prober. It is used for +// probing and checking the health status of the agent. +func agentHealthProber() *agentapi.HealthProber { + return &agentapi.HealthProber{ + Type: agentapi.HealthProberTypeWork, + WorkProber: &agentapi.WorkHealthProber{ + ProbeFields: []agentapi.ProbeField{ + { + ResourceIdentifier: workapiv1.ResourceIdentifier{ + Group: "apps", + Resource: "deployments", + Name: "cluster-auth-agent", + Namespace: common.AddonAgentInstallNamespace, + }, + ProbeRules: []workapiv1.FeedbackRule{ + { + Type: workapiv1.WellKnownStatusType, + }, + }, + }, + }, + HealthCheck: func(identifier workapiv1.ResourceIdentifier, result workapiv1.StatusFeedbackResult) error { + if len(result.Values) == 0 { + return fmt.Errorf("no values are probed for deployment %s/%s", identifier.Namespace, identifier.Name) + } + for _, value := range result.Values { + if value.Name != "ReadyReplicas" { + continue + } + + if *value.Value.Integer >= 1 { + return nil + } + return fmt.Errorf("readyReplica is %d for deployement %s/%s", *value.Value.Integer, identifier.Namespace, identifier.Name) + } + return fmt.Errorf("readyReplica is not probed") + }, + }, + } +} diff --git a/pkg/cmds/manager/main.go b/pkg/cmds/manager/main.go index 309fa3d9..f0f142ca 100644 --- a/pkg/cmds/manager/main.go +++ b/pkg/cmds/manager/main.go @@ -37,6 +37,7 @@ import ( "open-cluster-management.io/addon-framework/pkg/addonfactory" "open-cluster-management.io/addon-framework/pkg/addonmanager" "open-cluster-management.io/addon-framework/pkg/utils" + "open-cluster-management.io/api/addon/v1alpha1" clusterv1 "open-cluster-management.io/api/cluster/v1" clusterv1beta2 "open-cluster-management.io/api/cluster/v1beta2" workv1 "open-cluster-management.io/api/work/v1" @@ -115,6 +116,8 @@ func NewCmdManager() *cobra.Command { WithGetValuesFuncs( manager.GetDefaultValues(registryFQDN), ). + WithAgentHealthProber(agentHealthProber()). + WithAgentInstallNamespace(func(addon *v1alpha1.ManagedClusterAddOn) string { return common.AddonAgentInstallNamespace }). WithCreateAgentInstallNamespace(). BuildHelmAgentAddon() if err != nil { diff --git a/pkg/manager/agent-manifests/cluster-auth/templates/deployment.yaml b/pkg/manager/agent-manifests/cluster-auth/templates/deployment.yaml index 332c3743..c4dd277d 100644 --- a/pkg/manager/agent-manifests/cluster-auth/templates/deployment.yaml +++ b/pkg/manager/agent-manifests/cluster-auth/templates/deployment.yaml @@ -4,7 +4,7 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ include "cluster-auth.fullname" . }} + name: cluster-auth-agent namespace: {{ .Release.Namespace }} labels: {{- include "cluster-auth.labels" . | nindent 4 }}