diff --git a/Dockerfile b/Dockerfile index 25fb54a..3749d89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,23 @@ -FROM golang:1.20.2-alpine3.17 AS builder - -WORKDIR /app +FROM golang:1.21.2-alpine3.18 AS builder LABEL stage=gobuilder + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.sjtug.sjtu.edu.cn/g' /etc/apk/repositories && \ + apk update --no-cache && apk add --no-cache tzdata + ENV CGO_ENABLED 0 ENV GOARCH amd64 ENV GOPROXY https://goproxy.cn,direct +WORKDIR /app + +ADD go.mod . +ADD go.sum . +RUN go mod download COPY . . COPY etc/ /app/ -RUN go mod download RUN go build -o /app/pcm-participant-kubernetes /app/kubernetes.go - FROM alpine:3.16.2 WORKDIR /app diff --git a/internal/pkg/apply.go b/internal/pkg/apply.go index d376ee3..56f60c8 100644 --- a/internal/pkg/apply.go +++ b/internal/pkg/apply.go @@ -3,6 +3,7 @@ package pkg import ( "bytes" "context" + "github.com/zeromicro/go-zero/core/logx" "gitlink.org.cn/jcce-pcm/utils/tool" "io" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -26,6 +27,7 @@ func Apply(yamlString string, clientSet *kubernetes2.Clientset, dynamicClient dy break } if err != nil { + logx.Errorf("错误: %v", err) } obj := &unstructured.Unstructured{} syaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme).Decode(rawObj.Raw, nil, obj) @@ -35,9 +37,11 @@ func Apply(yamlString string, clientSet *kubernetes2.Clientset, dynamicClient dy unstructureObj := &unstructured.Unstructured{Object: unstructuredMap} gvr, err := tool.GetGVR(clientSet, unstructureObj.GroupVersionKind()) if err != nil { + logx.Errorf("GetGVR错误: %v", err) } unstructuredYaml, err := sigyaml.Marshal(unstructureObj) if err != nil { + logx.Errorf("错误: %v", err) } if unstructureObj.GetNamespace() == "" { @@ -47,6 +51,7 @@ func Apply(yamlString string, clientSet *kubernetes2.Clientset, dynamicClient dy if getErr != nil { _, createErr := dynamicClient.Resource(gvr).Namespace(unstructureObj.GetNamespace()).Create(context.Background(), unstructureObj, metav1.CreateOptions{}) if createErr != nil { + logx.Errorf("错误: %v", createErr) } }