Skip to content

Commit 8f309ca

Browse files
authored
Merge pull request kosmos-io#747 from OrangeBao/main
feat: add probe
2 parents 2d9c3f3 + 4a8c955 commit 8f309ca

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

cmd/kubenest/node-agent/app/serve/serve.go

+5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ func Start(addr, certFile, keyFile, user, password string) error {
6969
passwordHash := sha256.Sum256([]byte(password))
7070

7171
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
72+
if r.URL.Path == "/healthz" || r.URL.Path == "/readyz" {
73+
w.WriteHeader(http.StatusOK)
74+
return
75+
}
76+
7277
auth := r.Header.Get("Authorization")
7378
if auth == "" {
7479
http.Error(w, "Unauthorized", http.StatusUnauthorized)

cmd/kubenest/operator/app/operator.go

+14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
cliflag "k8s.io/component-base/cli/flag"
1616
"k8s.io/klog/v2"
1717
controllerruntime "sigs.k8s.io/controller-runtime"
18+
"sigs.k8s.io/controller-runtime/pkg/healthz"
1819
"sigs.k8s.io/controller-runtime/pkg/manager"
1920

2021
"github.com/kosmos.io/kosmos/cmd/kubenest/operator/app/config"
@@ -223,11 +224,24 @@ func run(ctx context.Context, config *config.Config) error {
223224
LeaderElection: config.LeaderElection.LeaderElect,
224225
LeaderElectionID: config.LeaderElection.ResourceName,
225226
LeaderElectionNamespace: config.LeaderElection.ResourceNamespace,
227+
LivenessEndpointName: "/healthz",
228+
ReadinessEndpointName: "/readyz",
229+
HealthProbeBindAddress: ":8081",
226230
})
227231
if err != nil {
228232
return fmt.Errorf("failed to build controller manager: %v", err)
229233
}
230234

235+
err = mgr.AddHealthzCheck("healthz", healthz.Ping)
236+
if err != nil {
237+
return fmt.Errorf("failed to build healthz: %v", err)
238+
}
239+
240+
err = mgr.AddReadyzCheck("readyz", healthz.Ping)
241+
if err != nil {
242+
return fmt.Errorf("failed to build readyz: %v", err)
243+
}
244+
231245
hostKubeClient, err := kubernetes.NewForConfig(config.RestConfig)
232246
if err != nil {
233247
return fmt.Errorf("could not create clientset: %v", err)

deploy/virtual-cluster-operator.yml

+47-6
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,37 @@ spec:
103103
values:
104104
- virtual-cluster-operator
105105
topologyKey: kubernetes.io/hostname
106+
initContainers:
107+
- name: init-container
108+
image: ghcr.io/kosmos-io/virtual-cluster-operator:__VERSION__
109+
command:
110+
- sh
111+
- "-c"
112+
- |
113+
mkdir -p /kosmos && \
114+
tar -xzf /config/manifest-use.tar -C /kosmos
115+
volumeMounts:
116+
- name: manifest-volume
117+
mountPath: /kosmos
118+
- name: manifest-tar
119+
mountPath: /config
106120
containers:
107121
- name: virtual-cluster-operator
108122
# Change a valid image address
109123
image: ghcr.io/kosmos-io/virtual-cluster-operator:__VERSION__
110124
imagePullPolicy: IfNotPresent
125+
livenessProbe:
126+
httpGet:
127+
path: /healthz
128+
port: 8081
129+
initialDelaySeconds: 15
130+
periodSeconds: 10
131+
readinessProbe:
132+
httpGet:
133+
path: /readyz
134+
port: 8081
135+
initialDelaySeconds: 5
136+
periodSeconds: 10
111137
env:
112138
- name: IMAGE_REPOSITIRY
113139
value: ghcr.io/kosmos-io
@@ -150,8 +176,8 @@ spec:
150176
- name: shellscript
151177
mountPath: /etc/vc-node-dir/config.yaml
152178
subPath: config.yaml
153-
- mountPath: /kosmos/manifest
154-
name: components-manifest
179+
- mountPath: /kosmos
180+
name: manifest-volume
155181
command:
156182
- virtual-cluster-operator
157183
- --kubeconfig=/etc/virtual-cluster-operator/kubeconfig
@@ -163,10 +189,11 @@ spec:
163189
- name: shellscript
164190
configMap:
165191
name: virtual-cluster-operator
166-
- hostPath:
167-
path: /home/vc-operator/manifest
168-
type: DirectoryOrCreate
169-
name: components-manifest
192+
- name: manifest-tar
193+
configMap:
194+
name: manifest-tar
195+
- name: manifest-volume
196+
emptyDir: {}
170197
---
171198
apiVersion: apps/v1
172199
kind: DaemonSet
@@ -216,6 +243,20 @@ spec:
216243
containers:
217244
- name: install-agent
218245
image: cis-hub-huabei-3.cmecloud.cn/node-agent/node-agent:latest
246+
livenessProbe:
247+
httpGet:
248+
path: /healthz
249+
port: 5678
250+
scheme: HTTPS
251+
initialDelaySeconds: 15
252+
periodSeconds: 10
253+
readinessProbe:
254+
httpGet:
255+
path: /readyz
256+
port: 5678
257+
scheme: HTTPS
258+
initialDelaySeconds: 5
259+
periodSeconds: 10
219260
securityContext:
220261
privileged: true # container privileged
221262
command:

0 commit comments

Comments
 (0)