Skip to content

Commit

Permalink
Add agentHealthProber
Browse files Browse the repository at this point in the history
Signed-off-by: Rokibul Hasan <[email protected]>
  • Loading branch information
RokibulHasan7 committed Mar 27, 2024
1 parent 47d289a commit 7421a95
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
51 changes: 51 additions & 0 deletions pkg/cmds/manager/helpers.go
Original file line number Diff line number Diff line change
@@ -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")
},
},
}
}
3 changes: 3 additions & 0 deletions pkg/cmds/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down

0 comments on commit 7421a95

Please sign in to comment.