This is an automated email from the ASF dual-hosted git repository.
ckj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git
The following commit(s) were added to refs/heads/master by this push:
new e1be8d64 [ISSUE-479] [operator] refine operator's build system (#491)
e1be8d64 is described below
commit e1be8d64fad928f5da75b6535309219e1ce20096
Author: advancedxy <[email protected]>
AuthorDate: Sun Jan 29 20:57:53 2023 +0800
[ISSUE-479] [operator] refine operator's build system (#491)
### What changes were proposed in this pull request?
1. image name defaults to rss-$module when no registry is specifed
2. upgrade envtest to 1.24.1 to support Apple M1 chips
3. modify Dockerfile to replace base image from alpine to debian slim
4. remove gorequest dep
5. modify go.mod and related changes to upgrade go version to 1.17
6. add new changes in auto-generated code(by go 1.17 and above)
### Why are the changes needed?
to address #479.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
No need
---
deploy/kubernetes/build-operator.sh | 2 +-
deploy/kubernetes/operator/Makefile | 22 ++++++--
.../api/uniffle/v1alpha1/zz_generated.deepcopy.go | 1 +
deploy/kubernetes/operator/go.mod | 66 ++++++++++++++++++++--
deploy/kubernetes/operator/go.sum | 9 ---
deploy/kubernetes/operator/hack/Dockerfile | 16 +++---
.../kubernetes/operator/pkg/webhook/util/util.go | 25 ++++++--
7 files changed, 108 insertions(+), 33 deletions(-)
diff --git a/deploy/kubernetes/build-operator.sh
b/deploy/kubernetes/build-operator.sh
index 7fde2d8c..47d356cd 100755
--- a/deploy/kubernetes/build-operator.sh
+++ b/deploy/kubernetes/build-operator.sh
@@ -20,4 +20,4 @@
echo "Build and Test kubernetes operator..."
# todo: separate the build process from test process, we need to modify the
Makefile
-cd operator && make build
+cd operator && make build docker-build
diff --git a/deploy/kubernetes/operator/Makefile
b/deploy/kubernetes/operator/Makefile
index f02969f0..bad51d7b 100644
--- a/deploy/kubernetes/operator/Makefile
+++ b/deploy/kubernetes/operator/Makefile
@@ -16,12 +16,16 @@
#
# REGISTRY URL to use all building/pushing image targets
-REGISTRY ?= UNKNOWN_REGISTRY
+REGISTRY ?= ''
+
+ifneq ('', ${REGISTRY})
+REGISTRY := $(addsuffix /, ${REGISTRY})
+endif
MODULES ?= webhook controller
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be
downloaded by envtest binary.
-ENVTEST_K8S_VERSION = 1.22.1
+ENVTEST_K8S_VERSION = 1.24.1
LOCAL_DIR=$(shell pwd)/local
@@ -32,6 +36,9 @@ else
GOBIN=$(shell go env GOBIN)
endif
+# set shell to bash
+SHELL := /bin/bash
+
.PHONY: all
all: build
@@ -47,7 +54,7 @@ generate: controller-gen ## Generate code containing
DeepCopy, DeepCopyInto, and
.PHONY: version
version:
@version=$(VERSION); \
- [[ "$$version" != "" ]] || version="$$(git describe --dirty --always
--tags | sed 's/-/./g')"; \
+ [ ! -z "$$version" ] || version="$$(git describe --dirty --always
--tags | sed 's/-/./g')"; \
if [[ $$version == *dirty ]]; then \
echo image version $$version is dirty, dirty files:; \
git diff; \
@@ -77,7 +84,10 @@ build: test ## Build manager binary.
# Build the docker image
docker-build: build version
@for module in ${MODULES}; do \
- image=${REGISTRY}/rss-$$module:$$(cat VERSION); \
+ echo registry is ${REGISTRY}; \
+ image_name=${REGISTRY}rss-$$module; \
+ echo image_name $$image_name; \
+ image=$$image_name:$$(cat VERSION); \
echo building $$image;\
docker build . -t $$image --build-arg MODULE=$$module -f
hack/Dockerfile; \
done
@@ -85,7 +95,9 @@ docker-build: build version
# Push the docker image
docker-push: docker-build
@for module in ${MODULES}; do \
- image=${REGISTRY}/rss-$$module:$$(cat VERSION); \
+ image_name=${REGISTRY}rss-$$module; \
+ echo image_name $$image_name; \
+ image=$$image_name:$$(cat VERSION); \
echo pushing $$image;\
docker push $$image; \
done
diff --git
a/deploy/kubernetes/operator/api/uniffle/v1alpha1/zz_generated.deepcopy.go
b/deploy/kubernetes/operator/api/uniffle/v1alpha1/zz_generated.deepcopy.go
index 0e17d5e9..77a99dbf 100644
--- a/deploy/kubernetes/operator/api/uniffle/v1alpha1/zz_generated.deepcopy.go
+++ b/deploy/kubernetes/operator/api/uniffle/v1alpha1/zz_generated.deepcopy.go
@@ -1,3 +1,4 @@
+//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*
diff --git a/deploy/kubernetes/operator/go.mod
b/deploy/kubernetes/operator/go.mod
index 853703b8..2d7500ee 100644
--- a/deploy/kubernetes/operator/go.mod
+++ b/deploy/kubernetes/operator/go.mod
@@ -1,13 +1,10 @@
module github.com/apache/incubator-uniffle/deploy/kubernetes/operator
-go 1.16
+go 1.17
require (
- github.com/fsnotify/fsnotify v1.5.1 // indirect
- github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/ginkgo/v2 v2.1.4
github.com/onsi/gomega v1.20.0
- github.com/parnurzeal/gorequest v0.2.16
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
gomodules.xyz/jsonpatch/v2 v2.2.0
k8s.io/api v0.22.2
@@ -16,6 +13,65 @@ require (
k8s.io/code-generator v0.22.2
k8s.io/klog/v2 v2.9.0
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
- moul.io/http2curl v1.0.0 // indirect
sigs.k8s.io/controller-runtime v0.10.0
)
+
+require (
+ github.com/PuerkitoBio/purell v1.1.1 // indirect
+ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 //
indirect
+ github.com/beorn7/perks v1.0.1 // indirect
+ github.com/cespare/xxhash/v2 v2.1.1 // indirect
+ github.com/davecgh/go-spew v1.1.1 // indirect
+ github.com/emicklei/go-restful v2.9.5+incompatible // indirect
+ github.com/evanphx/json-patch v4.11.0+incompatible // indirect
+ github.com/fsnotify/fsnotify v1.5.1 // indirect
+ github.com/go-logr/logr v0.4.0 // indirect
+ github.com/go-logr/zapr v0.4.0 // indirect
+ github.com/go-openapi/jsonpointer v0.19.5 // indirect
+ github.com/go-openapi/jsonreference v0.19.5 // indirect
+ github.com/go-openapi/swag v0.19.14 // indirect
+ github.com/gogo/protobuf v1.3.2 // indirect
+ github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da //
indirect
+ github.com/golang/protobuf v1.5.2 // indirect
+ github.com/google/go-cmp v0.5.8 // indirect
+ github.com/google/gofuzz v1.1.0 // indirect
+ github.com/google/uuid v1.1.2 // indirect
+ github.com/googleapis/gnostic v0.5.5 // indirect
+ github.com/imdario/mergo v0.3.12 // indirect
+ github.com/josharian/intern v1.0.0 // indirect
+ github.com/json-iterator/go v1.1.11 // indirect
+ github.com/mailru/easyjson v0.7.6 // indirect
+ github.com/matttproud/golang_protobuf_extensions
v1.0.2-0.20181231171920-c182affec369 // indirect
+ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd //
indirect
+ github.com/modern-go/reflect2 v1.0.1 // indirect
+ github.com/onsi/ginkgo v1.16.5 // indirect
+ github.com/pkg/errors v0.9.1 // indirect
+ github.com/prometheus/client_golang v1.11.0 // indirect
+ github.com/prometheus/client_model v0.2.0 // indirect
+ github.com/prometheus/common v0.26.0 // indirect
+ github.com/prometheus/procfs v0.6.0 // indirect
+ github.com/spf13/pflag v1.0.5 // indirect
+ go.uber.org/atomic v1.7.0 // indirect
+ go.uber.org/multierr v1.6.0 // indirect
+ go.uber.org/zap v1.19.0 // indirect
+ golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
+ golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
+ golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
+ golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
+ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
+ golang.org/x/text v0.3.7 // indirect
+ golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
+ golang.org/x/tools v0.1.10 // indirect
+ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
+ google.golang.org/appengine v1.6.7 // indirect
+ google.golang.org/protobuf v1.28.0 // indirect
+ gopkg.in/inf.v0 v0.9.1 // indirect
+ gopkg.in/yaml.v2 v2.4.0 // indirect
+ gopkg.in/yaml.v3 v3.0.1 // indirect
+ k8s.io/apiextensions-apiserver v0.22.1 // indirect
+ k8s.io/component-base v0.22.1 // indirect
+ k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 // indirect
+ k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e // indirect
+ sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
+ sigs.k8s.io/yaml v1.2.0 // indirect
+)
diff --git a/deploy/kubernetes/operator/go.sum
b/deploy/kubernetes/operator/go.sum
index 56a39259..323fbc2e 100644
--- a/deploy/kubernetes/operator/go.sum
+++ b/deploy/kubernetes/operator/go.sum
@@ -93,7 +93,6 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod
h1:E3ru+11k8xSBh+hMPgOLZm
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod
h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod
h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dustin/go-humanize v1.0.0/go.mod
h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
-github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153
h1:yUdfgN0XgIJw7foRItutHYUIhlcKzcSf5vDpdhQAKTc=
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod
h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod
h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/emicklei/go-restful v2.9.5+incompatible
h1:spTtZBk5DYEvbxMVutUuTyh1Ao2r4iyvLdACqsl/Ljk=
@@ -209,7 +208,6 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod
h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
github.com/googleapis/gnostic v0.5.1/go.mod
h1:6U4PtQXGIEt/Z3h5MAT7FNofLnw9vXk2cUuW7uA/OeU=
github.com/googleapis/gnostic v0.5.5
h1:9fHAtK0uDfpveeqqo1hkEZJcFvYXAiCN3UutL8F9xHw=
github.com/googleapis/gnostic v0.5.5/go.mod
h1:7+EbHbldMins07ALC74bsA81Ovc97DwqyJO1AENw9kA=
-github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1
h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod
h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.4.2/go.mod
h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod
h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
@@ -257,7 +255,6 @@ github.com/json-iterator/go v1.1.11
h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMW
github.com/json-iterator/go v1.1.11/go.mod
h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod
h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod
h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
-github.com/jtolds/gls v4.20.0+incompatible
h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod
h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod
h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod
h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
@@ -331,8 +328,6 @@ github.com/onsi/gomega v1.19.0/go.mod
h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9
github.com/onsi/gomega v1.20.0 h1:8W0cWlwFkflGPLltQvLRB7ZVD5HuP6ng320w2IS245Q=
github.com/onsi/gomega v1.20.0/go.mod
h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
github.com/opentracing/opentracing-go v1.1.0/go.mod
h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
-github.com/parnurzeal/gorequest v0.2.16
h1:T/5x+/4BT+nj+3eSknXmCTnEVGSzFzPGdpqmUVVZXHQ=
-github.com/parnurzeal/gorequest v0.2.16/go.mod
h1:3Kh2QUMJoqw3icWAecsyzkpY7UzRfDhbRdTjtNwNiUE=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod
h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.2.0/go.mod
h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod
h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
@@ -380,9 +375,7 @@ github.com/sirupsen/logrus v1.4.2/go.mod
h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
github.com/sirupsen/logrus v1.6.0/go.mod
h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.7.0/go.mod
h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.8.1/go.mod
h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
-github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d
h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod
h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
-github.com/smartystreets/goconvey v1.6.4
h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod
h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod
h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/soheilhy/cmux v0.1.5/go.mod
h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0=
@@ -812,8 +805,6 @@ k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod
h1:jPW/WVKK9YHAvNhRxK0md/
k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a/go.mod
h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
h1:HNSDgDCrr/6Ly3WEGKZftiE7IY19Vz2GdbOCyI4qqhc=
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9/go.mod
h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
-moul.io/http2curl v1.0.0 h1:6XwpyZOYsgZJrU8exnG87ncVkU1FVCcTRpwzOkTDUi8=
-moul.io/http2curl v1.0.0/go.mod h1:f6cULg+e4Md/oW1cYmwW4IWQOVl2lGbmCNGOHvzX2kE=
rsc.io/binaryregexp v0.2.0/go.mod
h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
diff --git a/deploy/kubernetes/operator/hack/Dockerfile
b/deploy/kubernetes/operator/hack/Dockerfile
index c5a7df0d..49ddca96 100644
--- a/deploy/kubernetes/operator/hack/Dockerfile
+++ b/deploy/kubernetes/operator/hack/Dockerfile
@@ -16,7 +16,7 @@
#
# Build the binary
-FROM golang:1.16 as builder
+FROM golang:1.17 as builder
ARG MODULE
WORKDIR /workspace
@@ -35,12 +35,12 @@ COPY pkg/ pkg/
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o
${MODULE} cmd/${MODULE}/main.go
-# Use distroless as minimal base image to package the manager binary
-# Refer to https://github.com/GoogleContainerTools/distroless for more details
-FROM alpine
-RUN apk add --update curl && \
- rm -rf /var/cache/apk/*
+
+FROM debian:11.6-slim
+# docker's ARG scope doc:
https://docs.docker.com/engine/reference/builder/#scope, it's required to
declear an arg in
+# each stage.
+ARG MODULE
WORKDIR /
COPY --from=builder /workspace/${MODULE} .
-
-CMD ["${MODULE}"]
+ENV OPERATOR_BIN=/${MODULE}
+ENTRYPOINT "/${OPERATOR_BIN}"
diff --git a/deploy/kubernetes/operator/pkg/webhook/util/util.go
b/deploy/kubernetes/operator/pkg/webhook/util/util.go
index f1425809..03837167 100644
--- a/deploy/kubernetes/operator/pkg/webhook/util/util.go
+++ b/deploy/kubernetes/operator/pkg/webhook/util/util.go
@@ -20,11 +20,11 @@ package util
import (
"encoding/json"
"fmt"
+ "io"
"io/ioutil"
"net/http"
"time"
- "github.com/parnurzeal/gorequest"
admissionv1 "k8s.io/api/admission/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -43,6 +43,10 @@ var (
codecs = serializer.NewCodecFactory(runtimeScheme)
// Deserializer attempts to load an object from data
deserializer = codecs.UniversalDeserializer()
+ httpClient = http.Client{
+ Timeout: time.Second * 15,
+ }
+ jsonContentType = "application/json"
)
// AdmissionReviewHandler handles AdmissionReviews and set response in them.
@@ -192,16 +196,27 @@ func HasZeroApps(pod *corev1.Pod) bool {
return true
}
url := fmt.Sprintf("http://%v:%v/metrics/server", pod.Status.PodIP,
port)
- req := gorequest.New().Timeout(time.Second * 15).Get(url).Type("json")
- resp, body, errs := req.EndBytes()
- if len(errs) > 0 {
- klog.Errorf("send metrics server request failed: %v->%+v", url,
errs)
+ req, err := http.NewRequest("GET", url, nil)
+ if err != nil {
+ klog.Errorf("new request failed with error: %v->%+v", url, err)
+ return true
+ }
+ // the request accept json response only
+ req.Header.Set("Accept", jsonContentType)
+ resp, err := httpClient.Do(req)
+ if err != nil {
+ klog.Errorf("send metrics server request failed: %v->%+v", url,
err)
return true
}
if resp.StatusCode != http.StatusOK {
klog.Errorf("heartbeat response failed: invalid status
(%v->%v)", url, resp.Status)
return false
}
+ body, err := io.ReadAll(resp.Body)
+ if err != nil {
+ klog.Errorf("heartbeat response failed: read body with
err:%+v", err)
+ return false
+ }
if num, err := getLastAppNum(body); err != nil {
klog.Errorf("get last app number of (%v) failed: %v",
pod.Spec.NodeName, err)
return false