From 1cb909436705016c07f5cfceb11cbf03749bad12 Mon Sep 17 00:00:00 2001 From: gaoyuan Date: Fri, 29 Nov 2024 18:04:25 +0800 Subject: [PATCH] use mount instead --- cmd/kubenest/node-agent/app/serve/serve.go | 16 +++------------- deploy/virtual-cluster-operator.yml | 13 ++++++++----- hack/node-agent/init.sh | 15 --------------- 3 files changed, 11 insertions(+), 33 deletions(-) diff --git a/cmd/kubenest/node-agent/app/serve/serve.go b/cmd/kubenest/node-agent/app/serve/serve.go index 8c8582771..be23ed6e6 100644 --- a/cmd/kubenest/node-agent/app/serve/serve.go +++ b/cmd/kubenest/node-agent/app/serve/serve.go @@ -82,16 +82,11 @@ func serveCmdRun(_ *cobra.Command, _ []string) error { addr = ":" + port } - return Start(ctx, addr, certFile, keyFile, user, password) - // err := Start(ctx, addr, certFile, keyFile, user, password) - // if err != nil { - // log.Errorf("Start server failed: %v", err) - // } - // return err + return Start(addr, certFile, keyFile, user, password) } func heartbeatCheck(ctx context.Context, nodeName string) { - kubeconfigPath := "/srv/node-agent/kubeconfig" + kubeconfigPath := "/srv/node-agent/kubeconfigpath/kubeconfig" config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath) if err != nil { log.Errorf("Failed to load kubeconfig: %v", err) @@ -131,7 +126,7 @@ func heartbeatCheck(ctx context.Context, nodeName string) { } // start server -func Start(ctx context.Context, addr, certFile, keyFile, user, password string) error { +func Start(addr, certFile, keyFile, user, password string) error { passwordHash := sha256.Sum256([]byte(password)) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -209,11 +204,6 @@ func Start(ctx context.Context, addr, certFile, keyFile, user, password string) ReadHeaderTimeout: 10 * time.Second, } - // go func() { - // time.Sleep(30 * time.Second) - // _ = server.Close() - // }() - err := server.ListenAndServeTLS("", "") if err != nil { log.Errorf("failed to start server %v", err) diff --git a/deploy/virtual-cluster-operator.yml b/deploy/virtual-cluster-operator.yml index cfba72c97..abc09291e 100644 --- a/deploy/virtual-cluster-operator.yml +++ b/deploy/virtual-cluster-operator.yml @@ -230,11 +230,6 @@ spec: secretKeyRef: name: node-agent-secret key: password - - name: KUBECONFIG - valueFrom: - secretKeyRef: - name: virtual-cluster-operator - key: kubeconfig - name: NODE_NAME valueFrom: fieldRef: @@ -250,6 +245,10 @@ spec: - mountPath: /host-systemd name: systemd-path readOnly: false + - mountPath: /app/kubeconfigpath + name: kubeconfig + subPath: kubeconfig + readOnly: false containers: - name: install-agent image: cis-hub-huabei-3.cmecloud.cn/node-agent/node-agent:latest @@ -292,6 +291,10 @@ spec: hostPath: path: /etc/systemd/system type: DirectoryOrCreate + - name: kubeconfig + secret: + secretName: virtual-cluster-operator + --- apiVersion: v1 kind: Secret diff --git a/hack/node-agent/init.sh b/hack/node-agent/init.sh index 7ac920f32..dc1918bbe 100644 --- a/hack/node-agent/init.sh +++ b/hack/node-agent/init.sh @@ -1,19 +1,5 @@ #!/usr/bin/env bash -if [ -z "$KUBECONFIG" ]; then - echo "Error: KUBECONFIG_CONTENT is not set." - exit 1 -fi - -echo "$KUBECONFIG" > /app/kubeconfig -if [ $? -ne 0 ]; then - echo "Error: Failed to write kubeconfig to $KUBECONFIG." - exit 1 -fi - -echo "KUBECONFIG has been written to $KUBECONFIG." - - WEB_USER="$WEB_USER" sed -i 's/^WEB_USER=.*/WEB_USER="'"$WEB_USER"'"/' /app/agent.env WEB_PASS="$WEB_PASS" sed -i 's/^WEB_PASS=.*/WEB_PASS="'"$WEB_PASS"'"/' /app/agent.env WEB_PORT="$WEB_PORT" sed -i 's/^WEB_PORT=.*/WEB_PORT="'"$WEB_PORT"'"/' /app/agent.env @@ -23,4 +9,3 @@ sha256sum /app/node-agent > /app/node-agent.sum sha256sum /host-path/node-agent >> /app/node-agent.sum rsync -avz /app/ /host-path/ cp /app/node-agent.service /host-systemd/node-agent.service -