Skip to content

Commit

Permalink
Merge pull request #836 from rambohe-ch/support-mac-env
Browse files Browse the repository at this point in the history
[enhancemnt] support local up openyurt on mac machine
  • Loading branch information
kadisi authored May 20, 2022
2 parents bd31e2c + cccb862 commit 8ee8f4f
Show file tree
Hide file tree
Showing 41 changed files with 1,128 additions and 751 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ jobs:
run: |
go get sigs.k8s.io/[email protected]
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.20.7/bin/linux/amd64/kubectl && sudo install kubectl /usr/local/bin/kubectl
- name: Build Images
run: make docker-build
- name: Local Up Openyurt Cluster With Kind
run: bash hack/local_up_openyurt.sh

run: make local-up-openyurt
- name: Run e2e Tests
run: make e2e-tests
110 changes: 73 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

.PHONY: clean all release build
TARGET_PLATFORMS ?= linux/amd64
IMAGE_REPO ?= openyurt
IMAGE_TAG ?= $(shell git describe --abbrev=0 --tags)
GIT_COMMIT = $(shell git rev-parse HEAD)

ifeq ($(shell git tag --points-at ${GIT_COMMIT}),)
GIT_VERSION=$(IMAGE_TAG)-$(shell echo ${GIT_COMMIT} | cut -c 1-7)
else
GIT_VERSION=$(IMAGE_TAG)
endif

DOCKER_BUILD_ARGS = --build-arg GIT_VERSION=${GIT_VERSION}

ifeq (${REGION}, cn)
DOCKER_BUILD_ARGS += --build-arg GOPROXY=https://goproxy.cn --build-arg MIRROR_REPO=mirrors.aliyun.com
endif

.PHONY: clean all build

all: test build

Expand All @@ -37,46 +54,25 @@ fmt:
vet:
go vet ./pkg/... ./cmd/...

# Build binaries and docker images.
# NOTE: this rule can take time, as we build binaries inside containers
#
# ARGS:
# WHAT: list of components that will be compiled.
# ARCH: list of target architectures.
# REGION: in which region this rule is executed, if in mainland China,
# set it as cn.
#
# Examples:
# # compile yurthub, yurt-controller-manager and yurtctl-servant with
# # architectures arm64 and arm in the mainland China
# make release WHAT="yurthub yurt-controller-manager yurtctl-servant" ARCH="arm64 arm" REGION=cn
#
# # compile all components with all architectures (i.e., amd64, arm64, arm)
# make release
release:
bash hack/make-rules/release-images.sh

# push generated images during 'make release'
push:
bash hack/make-rules/push-images.sh

clean:
-rm -Rf _output
-rm -Rf dockerbuild

e2e:
hack/make-rules/build-e2e.sh

e2e-tests:
bash hack/run-e2e-tests.sh
# Start up OpenYurt cluster on local machine based on a Kind cluster
# And you can run the following command on different env by specify TARGET_PLATFORMS, default platform is linux/amd64
# - on centos env: make local-up-openyurt
# - on MACBook Pro M1: make local-up-openyurt TARGET_PLATFORMS=linux/arm64
local-up-openyurt:
YURT_VERSION=$(GIT_VERSION) bash hack/make-rules/local-up-openyurt.sh

# create multi-arch manifest
manifest:
bash hack/make-rules/release-manifest.sh
# Build all OpenYurt components images and then start up OpenYurt cluster on local machine based on a Kind cluster
# And you can run the following command on different env by specify TARGET_PLATFORMS, default platform is linux/amd64
# - on centos env: make docker-build-and-up-openyurt
# - on MACBook Pro M1: make docker-build-and-up-openyurt TARGET_PLATFORMS=linux/arm64
docker-build-and-up-openyurt: docker-build
YURT_VERSION=$(GIT_VERSION) bash hack/make-rules/local-up-openyurt.sh

# push generated manifest during 'make manifest'
push_manifest:
bash hack/make-rules/push-manifest.sh
e2e-tests:
bash hack/make-rules/run-e2e-tests.sh

install-golint: ## check golint if not exist install golint tools
ifeq (, $(shell which golangci-lint))
Expand All @@ -90,4 +86,44 @@ GOLINT_BIN=$(shell which golangci-lint)
endif

lint: install-golint ## Run go lint against code.
$(GOLINT_BIN) run -v
$(GOLINT_BIN) run -v

# Build the docker images only one arch(specify arch by TARGET_PLATFORMS env)
# - build linux/amd64 docker images:
# $# make docker-build TARGET_PLATFORMS=linux/amd64
# - build linux/arm64 docker images:
# $# make docker-build TARGET_PLATFORMS=linux/arm64
docker-build: docker-build-yurthub docker-build-yurt-controller-manager docker-build-yurt-tunnel-server docker-build-yurt-tunnel-agent docker-build-node-servant

docker-build-yurthub:
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurthub . -t ${IMAGE_REPO}/yurthub:${GIT_VERSION}

docker-build-yurt-controller-manager:
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-controller-manager . -t ${IMAGE_REPO}/yurt-controller-manager:${GIT_VERSION}

docker-build-yurt-tunnel-server:
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-server . -t ${IMAGE_REPO}/yurt-tunnel-server:${GIT_VERSION}

docker-build-yurt-tunnel-agent:
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-agent . -t ${IMAGE_REPO}/yurt-tunnel-agent:${GIT_VERSION}

docker-build-node-servant:
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-node-servant . -t ${IMAGE_REPO}/node-servant:${GIT_VERSION}

# Build and Push the docker images with multi-arch
docker-push: docker-push-yurthub docker-push-yurt-controller-manager docker-push-yurt-tunnel-server docker-push-yurt-tunnel-agent docker-push-node-servant

docker-push-yurthub:
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurthub . -t ${IMAGE_REPO}/yurthub:${GIT_VERSION}

docker-push-yurt-controller-manager:
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-controller-manager . -t ${IMAGE_REPO}/yurt-controller-manager:${GIT_VERSION}

docker-push-yurt-tunnel-server:
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-server . -t ${IMAGE_REPO}/yurt-tunnel-server:${GIT_VERSION}

docker-push-yurt-tunnel-agent:
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-tunnel-agent . -t ${IMAGE_REPO}/yurt-tunnel-agent:${GIT_VERSION}

docker-push-node-servant:
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile.yurt-node-servant . -t ${IMAGE_REPO}/node-servant:${GIT_VERSION}
78 changes: 78 additions & 0 deletions cmd/yurt-node-servant/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Copyright 2022 The OpenYurt Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package config

import (
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/klog/v2"

"github.com/openyurtio/openyurt/pkg/node-servant/config"
"github.com/openyurtio/openyurt/pkg/projectinfo"
)

// NewConfigCmd generates a new config command
func NewConfigCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "config",
Short: "manage configuration of OpenYurt cluster",
RunE: cobra.OnlyValidArgs,
ValidArgs: []string{"control-plane"},
Args: cobra.MaximumNArgs(1),
}
cmd.AddCommand(newCmdConfigControlPlane())

return cmd
}

func newCmdConfigControlPlane() *cobra.Command {
o := config.NewControlPlaneOptions()
cmd := &cobra.Command{
Use: "control-plane",
Short: "configure control-plane components like kube-apiserver and kube-controller-manager",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Printf("node-servant version: %#v\n", projectinfo.Get())
if o.Version {
return nil
}

cmd.Flags().VisitAll(func(flag *pflag.Flag) {
klog.Infof("FLAG: --%s=%q", flag.Name, flag.Value)
})

if err := o.Validate(); err != nil {
klog.Fatalf("validate options: %v", err)
}

runner, err := config.NewControlPlaneRunner(o)
if err != nil {
return err
}
if err := runner.Do(); err != nil {
return fmt.Errorf("failed to config control-plane, %v", err)
}

klog.Info("node-servant config control-plane success")
return nil
},
Args: cobra.NoArgs,
}
o.AddFlags(cmd.Flags())
return cmd
}
38 changes: 15 additions & 23 deletions cmd/yurt-node-servant/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ limitations under the License.
package convert

import (
"time"
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/klog/v2"

nodeconverter "github.com/openyurtio/openyurt/pkg/node-servant/convert"
)

const (
// defaultYurthubHealthCheckTimeout defines the default timeout for yurthub health check phase
defaultYurthubHealthCheckTimeout = 2 * time.Minute
"github.com/openyurtio/openyurt/pkg/projectinfo"
)

// NewConvertCmd generates a new convert command
Expand All @@ -37,8 +34,17 @@ func NewConvertCmd() *cobra.Command {
Use: "convert --working-mode",
Short: "",
Run: func(cmd *cobra.Command, args []string) {
if err := o.Complete(cmd.Flags()); err != nil {
klog.Fatalf("fail to complete the convert option: %s", err)
fmt.Printf("node-servant version: %#v\n", projectinfo.Get())
if o.Version {
return
}

cmd.Flags().VisitAll(func(flag *pflag.Flag) {
klog.Infof("FLAG: --%s=%q", flag.Name, flag.Value)
})

if err := o.Validate(); err != nil {
klog.Fatalf("validate options: %v", err)
}

converter := nodeconverter.NewConverterWithOptions(o)
Expand All @@ -49,21 +55,7 @@ func NewConvertCmd() *cobra.Command {
},
Args: cobra.NoArgs,
}
setFlags(cmd)
o.AddFlags(cmd.Flags())

return cmd
}

// setFlags sets flags.
func setFlags(cmd *cobra.Command) {
cmd.Flags().String("yurthub-image", "openyurt/yurthub:latest",
"The yurthub image.")
cmd.Flags().Duration("yurthub-healthcheck-timeout", defaultYurthubHealthCheckTimeout,
"The timeout for yurthub health check.")
cmd.Flags().StringP("kubeadm-conf-path", "k", "",
"The path to kubelet service conf that is used by kubelet component to join the cluster on the work node."+
"Support multiple values, will search in order until get the file.(e.g -k kbcfg1,kbcfg2)",
)
cmd.Flags().String("join-token", "", "The token used by yurthub for joining the cluster.")
cmd.Flags().String("working-mode", "edge", "The node type cloud/edge, effect yurthub workingMode.")
}
2 changes: 2 additions & 0 deletions cmd/yurt-node-servant/node-servant.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/spf13/cobra"

"github.com/openyurtio/openyurt/cmd/yurt-node-servant/config"
"github.com/openyurtio/openyurt/cmd/yurt-node-servant/convert"
preflightconvert "github.com/openyurtio/openyurt/cmd/yurt-node-servant/preflight-convert"
"github.com/openyurtio/openyurt/cmd/yurt-node-servant/revert"
Expand All @@ -46,6 +47,7 @@ func main() {
rootCmd.AddCommand(convert.NewConvertCmd())
rootCmd.AddCommand(revert.NewRevertCmd())
rootCmd.AddCommand(preflightconvert.NewxPreflightConvertCmd())
rootCmd.AddCommand(config.NewConfigCmd())

if err := rootCmd.Execute(); err != nil { // run command
os.Exit(1)
Expand Down
14 changes: 14 additions & 0 deletions hack/dockerfiles/Dockerfile.yurt-controller-manager
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# multi-arch image building for yurt-controller-manager

FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder
ADD . /build
ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO
WORKDIR /build/
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/yurt-controller-manager

FROM --platform=${TARGETPLATFORM} alpine:3.14
ARG TARGETOS TARGETARCH MIRROR_REPO
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \
apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/*
COPY --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-controller-manager /usr/local/bin/yurt-controller-manager
ENTRYPOINT ["/usr/local/bin/yurt-controller-manager"]
15 changes: 15 additions & 0 deletions hack/dockerfiles/Dockerfile.yurt-node-servant
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# multi-arch image building for yurt-node-servant

FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder
ADD . /build
ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO
WORKDIR /build/
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/yurt-node-servant

FROM --platform=${TARGETPLATFORM} alpine:3.14
ARG TARGETOS TARGETARCH MIRROR_REPO
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \
apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/*
COPY --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-node-servant /usr/local/bin/node-servant
COPY hack/lib/node-servant-entry.sh /usr/local/bin/entry.sh
RUN chmod +x /usr/local/bin/entry.sh
14 changes: 14 additions & 0 deletions hack/dockerfiles/Dockerfile.yurt-tunnel-agent
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# multi-arch image building for yurt-tunnel-agent

FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder
ADD . /build
ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO
WORKDIR /build/
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/yurt-tunnel-agent

FROM --platform=${TARGETPLATFORM} alpine:3.14
ARG TARGETOS TARGETARCH MIRROR_REPO
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \
apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/*
COPY --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-tunnel-agent /usr/local/bin/yurt-tunnel-agent
ENTRYPOINT ["/usr/local/bin/yurt-tunnel-agent"]
14 changes: 14 additions & 0 deletions hack/dockerfiles/Dockerfile.yurt-tunnel-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# multi-arch image building for yurt-tunnel-server

FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder
ADD . /build
ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO
WORKDIR /build/
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/yurt-tunnel-server

FROM --platform=${TARGETPLATFORM} alpine:3.14
ARG TARGETOS TARGETARCH MIRROR_REPO
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \
apk add ca-certificates bash libc6-compat iptables ip6tables && update-ca-certificates && rm /var/cache/apk/*
COPY --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-tunnel-server /usr/local/bin/yurt-tunnel-server
ENTRYPOINT ["/usr/local/bin/yurt-tunnel-server"]
14 changes: 14 additions & 0 deletions hack/dockerfiles/Dockerfile.yurthub
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# multi-arch image building for yurthub

FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder
ADD . /build
ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO
WORKDIR /build/
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build WHAT=cmd/yurthub

FROM --platform=${TARGETPLATFORM} alpine:3.14
ARG TARGETOS TARGETARCH MIRROR_REPO
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \
apk add ca-certificates bash libc6-compat iptables ip6tables && update-ca-certificates && rm /var/cache/apk/*
COPY --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurthub /usr/local/bin/yurthub
ENTRYPOINT ["/usr/local/bin/yurthub"]
Loading

0 comments on commit 8ee8f4f

Please sign in to comment.