Skip to content

Commit

Permalink
fix: cmd execute exit code formate improve and add make node-agent ta…
Browse files Browse the repository at this point in the history
…rget

Signed-off-by: wangdepeng <[email protected]>
(cherry picked from commit 5853e67)
  • Loading branch information
village-way committed Apr 29, 2024
1 parent 5eb2ed8 commit 9358e23
Show file tree
Hide file tree
Showing 27 changed files with 77 additions and 190 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ MACOS_TARGETS := clusterlink-controller-manager \
clusterlink-proxy \
clustertree-cluster-manager \
virtual-cluster-operator \
node-agent \
scheduler \

# clusterlink-agent and clusterlink-floater only support linux platform
Expand All @@ -28,6 +29,7 @@ TARGETS := clusterlink-controller-manager \
clusterlink-proxy \
clustertree-cluster-manager \
virtual-cluster-operator \
node-agent \
scheduler \

# If GOOS is macOS, assign the value of MACOS_TARGETS to TARGETS
Expand Down Expand Up @@ -126,6 +128,7 @@ upload-images: images
docker push ${REGISTRY}/clusterlink-elector:${VERSION}
docker push ${REGISTRY}/clustertree-cluster-manager:${VERSION}
docker push ${REGISTRY}/virtual-cluster-operator:${VERSION}
docker push ${REGISTRY}/node-agent:${VERSION}
docker push ${REGISTRY}/scheduler:${VERSION}

.PHONY: release
Expand Down
21 changes: 21 additions & 0 deletions cluster/images/agent.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM ubuntu:latest as release-env

ARG BINARY

WORKDIR /app
# copy install file to container
# build context is _output/xx/xx
COPY agent/* .

# install rsync
RUN apt-get update && apt-get install -y rsync pwgen openssl && \
openssl req -x509 -sha256 -new -nodes -days 3650 -newkey rsa:2048 -keyout key.pem -out cert.pem -subj "/C=CN/O=Kosmos/OU=Kosmos/CN=kosmos.io" && \
WEB_USER=agent && \
WEB_PASS=$(pwgen -y 12 1) && \
sed -i "s/{{WEB_USER}}/$WEB_USER/g" agent.env && \
sed -i "s/{{WEB_PASS}}/$WEB_PASS/g" agent.env

COPY ${BINARY} /app

# install command
CMD ["bash", "/app/install.sh", "/app"]
21 changes: 21 additions & 0 deletions cluster/images/buildx.agent.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM ubuntu:latest as release-env

ARG BINARY
ARG TARGETPLATFORM

WORKDIR /app
# copy install file to container
COPY ${TARGETPLATFORM}/agent/* .

# install rsync
RUN apt-get update && apt-get install -y rsync pwgen openssl && \
openssl req -x509 -sha256 -new -nodes -days 3650 -newkey rsa:2048 -keyout key.pem -out cert.pem -subj "/C=CN/O=Kosmos/OU=Kosmos/CN=kosmos.io" && \
WEB_USER=agent && \
WEB_PASS=$(pwgen -y 12 1) && \
sed -i "s/{{WEB_USER}}/$WEB_USER/g" agent.env && \
sed -i "s/{{WEB_PASS}}/$WEB_PASS/g" agent.env

COPY ${TARGETPLATFORM}/${BINARY} /app

# install command
CMD ["bash", "/app/install.sh", "/app"]
45 changes: 0 additions & 45 deletions cmd/kubenest/node-agent/Dockerfile

This file was deleted.

67 changes: 0 additions & 67 deletions cmd/kubenest/node-agent/daemonset.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/kubenest/node-agent/go/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func handleCmd(conn *websocket.Conn, params url.Values) {
out, err := cmd.CombinedOutput()
if err != nil {
log.Warnf("failed to execute command : %v", err)
_ = conn.WriteMessage(websocket.TextMessage, []byte(err.Error()))
_ = conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, fmt.Sprintf("%d", cmd.ProcessState.ExitCode())))
} else {
_ = conn.WriteMessage(websocket.TextMessage, out)
}
Expand Down
10 changes: 10 additions & 0 deletions cmd/kubenest/node-agent/go/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ func handleMessages(ws *websocket.Conn) {
}

func sendFile(ws *websocket.Conn, filePath string) {
//if file not exists, close connection
if _, err := os.Stat(filePath); os.IsNotExist(err) {
log.Printf("File not exists: %v", err)
err := ws.WriteMessage(websocket.BinaryMessage, []byte("EOF"))
if err != nil {
log.Printf("Write message error: %v", err)
}
return
}

file, err := os.Open(filePath)
if err != nil {
log.Printf("File open error: %v", err)
Expand Down
13 changes: 0 additions & 13 deletions cmd/kubenest/node-agent/go/go.mod

This file was deleted.

20 changes: 0 additions & 20 deletions cmd/kubenest/node-agent/go/go.sum

This file was deleted.

37 changes: 0 additions & 37 deletions cmd/kubenest/node-agent/node-shell.yaml

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ def create_self_signed_cert():
pkey.generate_key(crypto.TYPE_RSA, 2048)

cert = crypto.X509()
cert.get_subject().C = "CN" # country
cert.get_subject().ST = "JiangShu" # state
cert.get_subject().L = "ShuZhou" # city
cert.get_subject().O = "Kosmos" # object
cert.get_subject().OU = "Kosmos" # unit
cert.get_subject().CN = "kosmos.io" # domain
# country
cert.get_subject().C = "CN"
# object
cert.get_subject().O = "Kosmos"
# unit
cert.get_subject().OU = "Kosmos"
# domain
cert.get_subject().CN = "kosmos.io"

cert.set_serial_number(1000)
cert.gmtime_adj_notBefore(0)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
golang.org/x/sys v0.12.0
golang.org/x/time v0.3.0
golang.org/x/tools v0.13.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.26.3
k8s.io/apiextensions-apiserver v0.26.3
k8s.io/apimachinery v0.26.3
Expand Down Expand Up @@ -176,7 +177,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/cloud-provider v0.26.3 // indirect
k8s.io/csi-translation-lib v0.26.3 // indirect
k8s.io/dynamic-resource-allocation v0.0.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ function build_binary_for_platform() {
-ldflags "${LDFLAGS:-}" \
-o "_output/bin/${platform}/$target" \
"${target_pkg}"
# copy file
echo "${REPO_ROOT}/hack/node-agent" "_output/bin/${platform}/$target"
mkdir -p "_output/bin/${platform}/agent"
cp "${REPO_ROOT}/hack/node-agent"/* "_output/bin/${platform}/agent"
set +x
}

Expand Down
2 changes: 2 additions & 0 deletions hack/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function build_images() {
local dockerfile="Dockerfile"
if [[ "${target}" == "clusterlink-floater" ]]; then
dockerfile="floater.Dockerfile"
elif [[ "${target}" == "node-agent" ]]; then
dockerfile="agent.Dockerfile"
fi

# Preferentially use `docker build`. If we are building multi platform,
Expand Down
2 changes: 2 additions & 0 deletions hack/node-agent/agent.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WEB_USER={{WEB_USER}}
WEB_PASS={{WEB_PASS}}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions hack/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ function release_binary_for_platform() {
-ldflags "${LDFLAGS:-}" \
-o "_output/release/$target-${platform}" \
"${target_pkg}"
# copy node-agent files
mkdir -p "_output/release/$target-${platform}/agent"
cp "${REPO_ROOT}/hack/node-agent"/* "_output/release/$target-${platform}/agent"
set +x
}

Expand Down
1 change: 1 addition & 0 deletions hack/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ CLUSTERLINK_TARGET_SOURCE=(
clusterlink-controller-manager=cmd/clusterlink/controller-manager
clustertree-cluster-manager=cmd/clustertree/cluster-manager
virtual-cluster-operator=cmd/kubenest/operator
node-agent=cmd/kubenest/node-agent/go
kosmosctl=cmd/kosmosctl
)

Expand Down

0 comments on commit 9358e23

Please sign in to comment.