Skip to content

Commit

Permalink
use helm charts to install yurt-manager and yurthub components in loc…
Browse files Browse the repository at this point in the history
…al kind cluster instead of using yaml constants. (#2074)
  • Loading branch information
rambohe-ch authored Jun 10, 2024
1 parent e8444c0 commit d82b780
Show file tree
Hide file tree
Showing 20 changed files with 347 additions and 1,441 deletions.
30 changes: 28 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ CRD_OPTIONS ?= "crd:crdVersions=v1,maxDescLen=1000"
BUILD_KUSTOMIZE ?= _output/manifest
GOPROXY ?= $(shell go env GOPROXY)

# Dynamic detection of operating system and architecture
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m)
ifeq ($(ARCH),x86_64)
ARCH := amd64
endif

ifeq ($(shell git tag --points-at ${GIT_COMMIT}),)
GIT_VERSION=$(IMAGE_TAG)-$(shell echo ${GIT_COMMIT} | cut -c 1-7)
else
Expand Down Expand Up @@ -65,6 +72,10 @@ KUBECTL ?= $(LOCALBIN)/kubectl
YQ_VERSION := 4.13.2
YQ := $(shell command -v $(LOCALBIN)/yq 2> /dev/null)

HELM_VERSION ?= v3.9.3
HELM ?= $(LOCALBIN)/helm
HELM_BINARY_URL := https://get.helm.sh/helm-$(HELM_VERSION)-$(OS)-$(ARCH).tar.gz

.PHONY: clean all build test

all: test build
Expand Down Expand Up @@ -96,7 +107,7 @@ verify-mod:
hack/make-rules/verify_mod.sh

# Start up OpenYurt cluster on local machine based on a Kind cluster
local-up-openyurt:
local-up-openyurt: install-helm
KUBERNETESVERSION=${KUBERNETESVERSION} YURT_VERSION=$(GIT_VERSION) bash hack/make-rules/local-up-openyurt.sh

# Build all OpenYurt components images and then start up OpenYurt cluster on local machine based on a Kind cluster
Expand All @@ -113,6 +124,21 @@ docker-build-and-up-openyurt: docker-build
e2e-tests:
ENABLE_AUTONOMY_TESTS=${ENABLE_AUTONOMY_TESTS} TARGET_PLATFORMS=${TARGET_PLATFORMS} hack/make-rules/run-e2e-tests.sh


install-helm: $(LOCALBIN)
@echo "Checking Helm installation..."
@HELM_CURRENT_VERSION=$$($(HELM) version --template="{{ .Version }}" 2>/dev/null || echo ""); \
if [ "$$HELM_CURRENT_VERSION" != "$(HELM_VERSION)" ]; then \
echo "Installing or upgrading Helm to version $(HELM_VERSION) into $(LOCALBIN)"; \
curl -fsSL -o helm.tar.gz "$(HELM_BINARY_URL)"; \
tar -xzf helm.tar.gz; \
mv $(OS)-$(ARCH)/helm $(HELM); \
rm -rf $(OS)-$(ARCH); \
rm helm.tar.gz; \
else \
echo "Helm version $(HELM_VERSION) is already installed."; \
fi

install-golint: ## check golint if not exist install golint tools
ifeq ($(shell $(GLOBAL_GOLANGCILINT) version --format short), $(GOLANGCILINT_VERSION))
GOLINT_BIN=$(GLOBAL_GOLANGCILINT)
Expand Down Expand Up @@ -222,7 +248,7 @@ kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong ver
$(KUSTOMIZE): $(LOCALBIN)
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
rm -rf $(LOCALBIN)/kustomize; \
rm -f $(LOCALBIN)/kustomize; \
fi
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }

Expand Down
1 change: 0 additions & 1 deletion charts/yurt-manager/templates/yurt-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ spec:
- --metrics-addr=:{{ .Values.ports.metrics }}
- --health-probe-addr=:{{ .Values.ports.healthProbe }}
- --webhook-port={{ .Values.ports.webhook }}
- --logtostderr=true
- --v={{ .Values.log.level }}
- --working-namespace={{ .Release.Namespace }}
{{- if .Values.leaderElectResourceName }}
Expand Down
6 changes: 1 addition & 5 deletions hack/make-rules/local-up-openyurt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ readonly KUBERNETESVERSION=${KUBERNETESVERSION:-"v1.28"}
readonly NODES_NUM=${NODES_NUM:-3}
readonly KIND_KUBECONFIG=${KIND_KUBECONFIG:-${HOME}/.kube/config}
readonly DISABLE_DEFAULT_CNI=${DISABLE_DEFAULT_CNI:-"false"}
ENABLE_DUMMY_IF=true
if [[ "${LOCAL_OS}" == darwin ]]; then
ENABLE_DUMMY_IF=false
fi

function install_kind {
echo "Begin to install kind"
Expand Down Expand Up @@ -134,7 +130,7 @@ function local_up_openyurt {
$YURT_ROOT/test/e2e/e2e.test init \
--kubernetes-version=${KUBERNETESVERSION} --kube-config=${KIND_KUBECONFIG} \
--cluster-name=${CLUSTER_NAME} --openyurt-version=${YURT_VERSION} --use-local-images --ignore-error \
--node-num=${NODES_NUM} --enable-dummy-if=${ENABLE_DUMMY_IF} --disable-default-cni=${DISABLE_DEFAULT_CNI}
--node-num=${NODES_NUM} --disable-default-cni=${DISABLE_DEFAULT_CNI}
}

function cleanup {
Expand Down
44 changes: 0 additions & 44 deletions hack/make-rules/run-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ edgeNodeContainer2Name="openyurt-e2e-test-worker2"
KUBECONFIG=${KUBECONFIG:-${HOME}/.kube/config}
TARGET_PLATFORM=${TARGET_PLATFORMS:-linux/amd64}
ENABLE_AUTONOMY_TESTS=${ENABLE_AUTONOMY_TESTS:-true}
USE_LOCAL_CNI=${USE_LOCAL_CNI:-false}
SKIP_SETUP_NETWORK=${SKIP_SETUP_NETWORK:-false}

function set_flags() {
goldflags="${GOLDFLAGS:--s -w $(project_info)}"
Expand All @@ -45,44 +43,6 @@ function set_flags() {
docker cp $KUBECONFIG $edgeNodeContainerName:/root/.kube/config
}

# set up network
function set_up_network() {
# set up bridge cni plugins for every node
if [ "$USE_LOCAL_CNI" = "true" ]; then
if [ "$TARGET_PLATFORM" = "linux/amd64" ]; then
cp ${YURT_ROOT}/hack/cni/cni-plugins-linux-amd64-v1.4.1.tgz /tmp/cni.tgz
else
cp ${YURT_ROOT}/hack/cni/cni-plugins-linux-arm64-v1.4.1.tgz /tmp/cni.tgz
fi
else
if [ "$TARGET_PLATFORM" = "linux/amd64" ]; then
wget -O /tmp/cni.tgz https://github.com/containernetworking/plugins/releases/download/v1.4.1/cni-plugins-linux-amd64-v1.4.1.tgz
else
wget -O /tmp/cni.tgz https://github.com/containernetworking/plugins/releases/download/v1.4.1/cni-plugins-linux-arm64-v1.4.1.tgz
fi
fi


docker cp /tmp/cni.tgz $cloudNodeContainerName:/opt/cni/bin/
docker exec -t $cloudNodeContainerName /bin/bash -c 'cd /opt/cni/bin && tar -zxf cni.tgz'

docker cp /tmp/cni.tgz $edgeNodeContainerName:/opt/cni/bin/
docker exec -t $edgeNodeContainerName /bin/bash -c 'cd /opt/cni/bin && tar -zxf cni.tgz'

docker cp /tmp/cni.tgz $edgeNodeContainer2Name:/opt/cni/bin/
docker exec -t $edgeNodeContainer2Name /bin/bash -c 'cd /opt/cni/bin && tar -zxf cni.tgz'

# deploy flannel DaemonSet
local flannelYaml="https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml"
local flannelDs="kube-flannel-ds"
local flannelNameSpace="kube-flannel"
local POD_CREATE_TIMEOUT=120s
curl -o /tmp/flannel.yaml $flannelYaml
kubectl apply -f /tmp/flannel.yaml
# check if flannel on every node is ready, if so, "daemon set "kube-flannel-ds" successfully rolled out"
kubectl rollout status daemonset kube-flannel-ds -n kube-flannel --timeout=${POD_CREATE_TIMEOUT}
}

function cleanup {
rm -rf "$YURT_ROOT/test/e2e/e2e.test"
}
Expand Down Expand Up @@ -166,10 +126,6 @@ function prepare_autonomy_tests {

GOOS=${LOCAL_OS} GOARCH=${LOCAL_ARCH} set_flags

if [ "$SKIP_SETUP_NETWORK" != "true" ]; then
set_up_network
fi

cleanup

get_ginkgo
Expand Down
20 changes: 2 additions & 18 deletions pkg/node-servant/components/yurthub.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ import (

"github.com/openyurtio/openyurt/pkg/projectinfo"
kubeconfigutil "github.com/openyurtio/openyurt/pkg/util/kubeconfig"
tmplutil "github.com/openyurtio/openyurt/pkg/util/templates"
"github.com/openyurtio/openyurt/pkg/yurtadm/constants"
enutil "github.com/openyurtio/openyurt/pkg/yurtadm/util/edgenode"
"github.com/openyurtio/openyurt/pkg/yurthub/storage/disk"
"github.com/openyurtio/openyurt/pkg/yurthub/util"
)

const (
Expand All @@ -52,25 +50,16 @@ const (

type yurtHubOperator struct {
apiServerAddr string
yurthubImage string
joinToken string
workingMode util.WorkingMode
yurthubHealthCheckTimeout time.Duration
enableDummyIf bool
enableNodePool bool
}

// NewYurthubOperator new yurtHubOperator struct
func NewYurthubOperator(apiServerAddr string, yurthubImage string, joinToken string,
workingMode util.WorkingMode, yurthubHealthCheckTimeout time.Duration, enableDummyIf, enableNodePool bool) *yurtHubOperator {
func NewYurthubOperator(apiServerAddr string, joinToken string, yurthubHealthCheckTimeout time.Duration) *yurtHubOperator {
return &yurtHubOperator{
apiServerAddr: apiServerAddr,
yurthubImage: yurthubImage,
joinToken: joinToken,
workingMode: workingMode,
yurthubHealthCheckTimeout: yurthubHealthCheckTimeout,
enableDummyIf: enableDummyIf,
enableNodePool: enableNodePool,
}
}

Expand Down Expand Up @@ -101,12 +90,7 @@ func (op *yurtHubOperator) Install() error {
return fmt.Errorf("could not read source file %s: %w", configMapDataPath, err)
}
klog.Infof("yurt-hub.yaml apiServerAddr: %+v", op.apiServerAddr)
yssYurtHub, err := tmplutil.SubsituteTemplate(string(content), map[string]string{
"kubernetesServerAddr": op.apiServerAddr,
})
if err != nil {
return err
}
yssYurtHub := strings.ReplaceAll(string(content), "KUBERNETES_SERVER_ADDRESS", op.apiServerAddr)
if err = os.WriteFile(getYurthubYaml(podManifestPath), []byte(yssYurtHub), fileMode); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/node-servant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ spec:
- /bin/sh
- -c
args:
- "/usr/local/bin/entry.sh convert --working-mode={{.working_mode}} --yurthub-image={{.yurthub_image}} {{if .yurthub_healthcheck_timeout}}--yurthub-healthcheck-timeout={{.yurthub_healthcheck_timeout}} {{end}}--join-token={{.joinToken}} {{if .enable_dummy_if}}--enable-dummy-if={{.enable_dummy_if}}{{end}} {{if .enable_node_pool}}--enable-node-pool={{.enable_node_pool}}{{end}}"
- "/usr/local/bin/entry.sh convert {{if .yurthub_healthcheck_timeout}}--yurthub-healthcheck-timeout={{.yurthub_healthcheck_timeout}} {{end}}--join-token={{.joinToken}}"
securityContext:
privileged: true
volumeMounts:
Expand Down
12 changes: 1 addition & 11 deletions pkg/node-servant/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,14 @@ import (
"time"

"github.com/openyurtio/openyurt/pkg/node-servant/components"
"github.com/openyurtio/openyurt/pkg/yurthub/util"
)

// Config has the information that required by convert operation
type Config struct {
yurthubImage string
yurthubHealthCheckTimeout time.Duration
workingMode util.WorkingMode
joinToken string
kubeadmConfPaths []string
openyurtDir string
enableDummyIf bool
enableNodePool bool
}

// nodeConverter do the convert job
Expand All @@ -46,14 +41,10 @@ type nodeConverter struct {
func NewConverterWithOptions(o *Options) *nodeConverter {
return &nodeConverter{
Config: Config{
yurthubImage: o.yurthubImage,
yurthubHealthCheckTimeout: o.yurthubHealthCheckTimeout,
workingMode: util.WorkingMode(o.workingMode),
joinToken: o.joinToken,
kubeadmConfPaths: strings.Split(o.kubeadmConfPaths, ","),
openyurtDir: o.openyurtDir,
enableDummyIf: o.enableDummyIf,
enableNodePool: o.enableNodePool,
},
}
}
Expand All @@ -79,8 +70,7 @@ func (n *nodeConverter) installYurtHub() error {
if apiServerAddress == "" {
return fmt.Errorf("get apiServerAddress empty")
}
op := components.NewYurthubOperator(apiServerAddress, n.yurthubImage, n.joinToken,
n.workingMode, n.yurthubHealthCheckTimeout, n.enableDummyIf, n.enableNodePool)
op := components.NewYurthubOperator(apiServerAddress, n.joinToken, n.yurthubHealthCheckTimeout)
return op.Install()
}

Expand Down
17 changes: 0 additions & 17 deletions pkg/node-servant/convert/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

"github.com/openyurtio/openyurt/pkg/node-servant/components"
"github.com/openyurtio/openyurt/pkg/yurtadm/constants"
hubutil "github.com/openyurtio/openyurt/pkg/yurthub/util"
)

const (
Expand All @@ -35,27 +34,19 @@ const (

// Options has the information that required by convert operation
type Options struct {
yurthubImage string
yurthubHealthCheckTimeout time.Duration
workingMode string
joinToken string
kubeadmConfPaths string
openyurtDir string
enableDummyIf bool
enableNodePool bool
Version bool
}

// NewConvertOptions creates a new Options
func NewConvertOptions() *Options {
return &Options{
yurthubImage: "openyurt/yurthub:latest",
yurthubHealthCheckTimeout: defaultYurthubHealthCheckTimeout,
workingMode: string(hubutil.WorkingModeEdge),
kubeadmConfPaths: strings.Join(components.GetDefaultKubeadmConfPath(), ","),
openyurtDir: constants.OpenyurtDir,
enableDummyIf: true,
enableNodePool: true,
}
}

Expand All @@ -65,21 +56,13 @@ func (o *Options) Validate() error {
return fmt.Errorf("join token(bootstrap token) is empty")
}

if !hubutil.IsSupportedWorkingMode(hubutil.WorkingMode(o.workingMode)) {
return fmt.Errorf("workingMode must be pointed out as cloud or edge. got %s", o.workingMode)
}

return nil
}

// AddFlags sets flags.
func (o *Options) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&o.yurthubImage, "yurthub-image", o.yurthubImage, "The yurthub image.")
fs.DurationVar(&o.yurthubHealthCheckTimeout, "yurthub-healthcheck-timeout", o.yurthubHealthCheckTimeout, "The timeout for yurthub health check.")
fs.StringVarP(&o.kubeadmConfPaths, "kubeadm-conf-path", "k", o.kubeadmConfPaths, "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)")
fs.StringVar(&o.joinToken, "join-token", o.joinToken, "The token used by yurthub for joining the cluster.")
fs.StringVar(&o.workingMode, "working-mode", o.workingMode, "The node type cloud/edge, effect yurthub workingMode.")
fs.BoolVar(&o.enableDummyIf, "enable-dummy-if", o.enableDummyIf, "Enable dummy interface for yurthub or not.")
fs.BoolVar(&o.enableNodePool, "enable-node-pool", o.enableNodePool, "Enable list/watch nodepools for yurthub or not.")
fs.BoolVar(&o.Version, "version", o.Version, "print the version information.")
}
2 changes: 1 addition & 1 deletion pkg/node-servant/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func validate(action string, tmplCtx map[string]string, nodeName string) error {

switch action {
case "convert":
keysMustHave := []string{"node_servant_image", "yurthub_image", "joinToken"}
keysMustHave := []string{"node_servant_image", "joinToken"}
return checkKeys(keysMustHave, tmplCtx)
case "revert":
keysMustHave := []string{"node_servant_image"}
Expand Down
4 changes: 1 addition & 3 deletions pkg/node-servant/revert/revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"time"

"github.com/openyurtio/openyurt/pkg/node-servant/components"
"github.com/openyurtio/openyurt/pkg/yurthub/util"
)

// NodeReverter do the revert job
Expand Down Expand Up @@ -61,8 +60,7 @@ func (n *nodeReverter) revertKubelet() error {
}

func (n *nodeReverter) unInstallYurtHub() error {
op := components.NewYurthubOperator("", "", "",
util.WorkingModeCloud, time.Duration(1), true, true) // params is not important here
op := components.NewYurthubOperator("", "", time.Duration(1)) // params is not important here
return op.UnInstall()
}

Expand Down
Loading

0 comments on commit d82b780

Please sign in to comment.