Skip to content

Commit

Permalink
use mount instead
Browse files Browse the repository at this point in the history
  • Loading branch information
gao12312 committed Nov 29, 2024
1 parent 8610dc2 commit 1cb9094
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 33 deletions.
16 changes: 3 additions & 13 deletions cmd/kubenest/node-agent/app/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions deploy/virtual-cluster-operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -292,6 +291,10 @@ spec:
hostPath:
path: /etc/systemd/system
type: DirectoryOrCreate
- name: kubeconfig
secret:
secretName: virtual-cluster-operator

---
apiVersion: v1
kind: Secret
Expand Down
15 changes: 0 additions & 15 deletions hack/node-agent/init.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit 1cb9094

Please sign in to comment.