-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmanager.go
103 lines (90 loc) · 2.95 KB
/
manager.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package controller
import (
"embed"
"fmt"
"os"
"k8s.io/client-go/rest"
"open-cluster-management.io/addon-framework/pkg/addonfactory"
"open-cluster-management.io/addon-framework/pkg/agent"
"open-cluster-management.io/addon-framework/pkg/utils"
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
clusterv1 "open-cluster-management.io/api/cluster/v1"
workapiv1 "open-cluster-management.io/api/work/v1"
"github.com/kubestellar/ocm-status-addon/pkg/rbac"
)
const (
DefaultStatusAddOnImage = "quay.io/pdettori/status-addon:0.1.0"
AddonName = "addon-status"
InstallationNamespace = "open-cluster-management-agent-addon"
)
//go:embed manifests
//go:embed manifests/templates
var FS embed.FS
func NewRegistrationOption(kubeConfig *rest.Config, addonName, agentName string) *agent.RegistrationOption {
return &agent.RegistrationOption{
CSRConfigurations: agent.KubeClientSignerConfigurations(addonName, agentName),
CSRApproveCheck: utils.DefaultCSRApprover(agentName),
PermissionConfig: rbac.AddonRBAC(kubeConfig),
Namespace: InstallationNamespace,
}
}
func GetDefaultValues(cluster *clusterv1.ManagedCluster,
addon *addonapiv1alpha1.ManagedClusterAddOn) (addonfactory.Values, error) {
installNamespace := addon.Spec.InstallNamespace
if len(installNamespace) == 0 {
installNamespace = InstallationNamespace
}
image := os.Getenv("STATUS_ADDDON_IMAGE_NAME")
if len(image) == 0 {
image = DefaultStatusAddOnImage
}
manifestConfig := struct {
KubeConfigSecret string
ClusterName string
AddonInstallNamespace string
Image string
}{
KubeConfigSecret: fmt.Sprintf("%s-hub-kubeconfig", addon.Name),
AddonInstallNamespace: installNamespace,
ClusterName: cluster.Name,
Image: image,
}
return addonfactory.StructToValues(manifestConfig), nil
}
func AgentHealthProber() *agent.HealthProber {
return &agent.HealthProber{
Type: agent.HealthProberTypeWork,
WorkProber: &agent.WorkHealthProber{
ProbeFields: []agent.ProbeField{
{
ResourceIdentifier: workapiv1.ResourceIdentifier{
Group: "apps",
Resource: "deployments",
Name: "status-agent",
Namespace: InstallationNamespace,
},
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")
},
},
}
}