Skip to content

Commit

Permalink
feat: add probe
Browse files Browse the repository at this point in the history
Signed-off-by: baoyinghai_yewu <[email protected]>
  • Loading branch information
OrangeBao committed Oct 8, 2024
1 parent 7e519b3 commit 801d876
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 91 deletions.
5 changes: 5 additions & 0 deletions cmd/kubenest/node-agent/app/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func Start(addr, certFile, keyFile, user, password string) error {
passwordHash := sha256.Sum256([]byte(password))

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/healthz" || r.URL.Path == "/readyz" {
w.WriteHeader(http.StatusOK)
return
}

auth := r.Header.Get("Authorization")
if auth == "" {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
Expand Down
14 changes: 14 additions & 0 deletions cmd/kubenest/operator/app/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/klog/v2"
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/manager"

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

err = mgr.AddHealthzCheck("healthz", healthz.Ping)
if err != nil {
return fmt.Errorf("failed to build healthz: %v", err)
}

err = mgr.AddReadyzCheck("readyz", healthz.Ping)
if err != nil {
return fmt.Errorf("failed to build readyz: %v", err)
}

hostKubeClient, err := kubernetes.NewForConfig(config.RestConfig)
if err != nil {
return fmt.Errorf("could not create clientset: %v", err)
Expand Down
53 changes: 47 additions & 6 deletions deploy/virtual-cluster-operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,37 @@ spec:
values:
- virtual-cluster-operator
topologyKey: kubernetes.io/hostname
initContainers:
- name: init-container
image: ghcr.io/kosmos-io/virtual-cluster-operator:__VERSION__
command:
- sh
- "-c"
- |
mkdir -p /kosmos && \
tar -xzf /config/manifest-use.tar -C /kosmos
volumeMounts:
- name: manifest-volume
mountPath: /kosmos
- name: manifest-tar
mountPath: /config
containers:
- name: virtual-cluster-operator
# Change a valid image address
image: ghcr.io/kosmos-io/virtual-cluster-operator:__VERSION__
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 15
periodSeconds: 10
readinessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
env:
- name: IMAGE_REPOSITIRY
value: ghcr.io/kosmos-io
Expand Down Expand Up @@ -150,8 +176,8 @@ spec:
- name: shellscript
mountPath: /etc/vc-node-dir/config.yaml
subPath: config.yaml
- mountPath: /kosmos/manifest
name: components-manifest
- mountPath: /kosmos
name: manifest-volume
command:
- virtual-cluster-operator
- --kubeconfig=/etc/virtual-cluster-operator/kubeconfig
Expand All @@ -163,10 +189,11 @@ spec:
- name: shellscript
configMap:
name: virtual-cluster-operator
- hostPath:
path: /home/vc-operator/manifest
type: DirectoryOrCreate
name: components-manifest
- name: manifest-tar
configMap:
name: manifest-tar
- name: manifest-volume
emptyDir: {}
---
apiVersion: apps/v1
kind: DaemonSet
Expand Down Expand Up @@ -216,6 +243,20 @@ spec:
containers:
- name: install-agent
image: cis-hub-huabei-3.cmecloud.cn/node-agent/node-agent:latest
livenessProbe:
httpGet:
path: /healthz
port: 5678
scheme: HTTPS
initialDelaySeconds: 15
periodSeconds: 10
readinessProbe:
httpGet:
path: /readyz
port: 5678
scheme: HTTPS
initialDelaySeconds: 5
periodSeconds: 10
securityContext:
privileged: true # container privileged
command:
Expand Down
85 changes: 0 additions & 85 deletions hack/k8s-in-k8s/g.env.sh

This file was deleted.

0 comments on commit 801d876

Please sign in to comment.