Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade crd in the initContainer #2076

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ rules:
resources:
- customresourcedefinitions
verbs:
- create
- get
- list
- patch
Expand Down
4 changes: 4 additions & 0 deletions charts/yurt-manager/templates/yurt-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ spec:
key: node-role.kubernetes.io/master
- effect: NoSchedule
key: node-role.kubernetes.io/control-plane
initContainers:
- image: {{ .Values.initImage.registry }}/{{ .Values.initImage.repository }}:{{ .Values.initImage.tag }}
name: crd-upgrader
imagePullPolicy: IfNotPresent
containers:
- args:
- --metrics-addr=:{{ .Values.ports.metrics }}
Expand Down
8 changes: 8 additions & 0 deletions charts/yurt-manager/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ image:
# pullSecrets:
# - name: myRegistryKeySecretName

initImage:
registry: openyurt
repository: crd-upgrader
tag: v1.4.0
pullSecrets: []
# pullSecrets:
# - name: myRegistryKeySecretName

ports:
metrics: 10271
healthProbe: 10272
Expand Down
2 changes: 1 addition & 1 deletion hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 The OpenYurt Authors.
Copyright 2024 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.
Expand Down
11 changes: 11 additions & 0 deletions hack/dockerfiles/build/Dockerfile.crd-upgrader
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM bitnami/kubectl:1.29

# Add the CRD installation script to the container
COPY ./hack/make-rules/crd_upgrader.sh /usr/local/bin/crd-upgrade.sh

# Add CRD YAML files to the container
COPY ./charts/yurt-manager/crds /crds
COPY ./charts/yurt-iot-dock/crds /crds

# Set the entrypoint to the CRD installation script
ENTRYPOINT ["/usr/local/bin/crd-upgrade.sh"]
11 changes: 11 additions & 0 deletions hack/dockerfiles/release/Dockerfile.crd-upgrader
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM bitnami/kubectl:1.29

# Add the CRD installation script to the container
COPY ./hack/make-rules/crd_upgrader.sh /usr/local/bin/crd-upgrade.sh

# Add CRD YAML files to the container
COPY ./charts/yurt-manager/crds /crds
COPY ./charts/yurt-iot-dock/crds /crds

# Set the entrypoint to the CRD installation script
ENTRYPOINT ["/usr/local/bin/crd-upgrade.sh"]
27 changes: 27 additions & 0 deletions hack/make-rules/crd_upgrader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

# Copyright 2024 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.

set -x
set -e

CRD_DIR="/crds"

for crd in "$CRD_DIR"/*.yaml; do
echo "Applying CRD: $crd"
kubectl apply --server-side -f "$crd"
done

echo "CRDs successfully applied."
15 changes: 15 additions & 0 deletions hack/make-rules/image_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ readonly IMAGE_TARGETS=(
yurt-iot-dock
)

readonly INIT_IMAGE_TARGETS=(
crd-upgrader
)

http_proxy=${http_proxy:-}
https_proxy=${https_proxy:-}
targets=${@:-${IMAGE_TARGETS[@]}}
init_targets=${@:-${INIT_IMAGE_TARGETS[@]}}
REGION=${REGION:-}
IMAGE_REPO=${IMAGE_REPO:-"openyurt"}
IMAGE_TAG=${IMAGE_TAG:-$(get_image_tag)}
Expand Down Expand Up @@ -98,3 +103,13 @@ for image in ${targets[@]}; do
--tag ${IMAGE_REPO}/${image}:${IMAGE_TAG} \
${YURT_ROOT}
done

for image in ${init_targets[@]}; do
docker buildx build \
--no-cache \
--load ${DOCKER_BUILD_ARGS} \
--platform ${TARGET_PLATFORMS} \
--file ${YURT_ROOT}/hack/dockerfiles/build/Dockerfile.${image} \
--tag ${IMAGE_REPO}/${image}:${IMAGE_TAG} \
${YURT_ROOT}
done
2 changes: 1 addition & 1 deletion pkg/yurtmanager/webhook/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ type GateFunc func() (enabled bool)
// +kubebuilder:rbac:groups=core,namespace=kube-system,resources=secrets,verbs=get;update
// +kubebuilder:rbac:groups=admissionregistration.k8s.io,resources=mutatingwebhookconfigurations,verbs=get;list;watch;update;patch
// +kubebuilder:rbac:groups=admissionregistration.k8s.io,resources=validatingwebhookconfigurations,verbs=get;list;watch;update;patch
// +kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=get;list;watch;update;patch
// +kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=get;list;watch;update;patch;create

func Initialize(ctx context.Context, cc *config.CompletedConfig, restCfg *rest.Config) error {
c, err := webhookcontroller.New(WebhookHandlerPath, cc, restCfg)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/cmd/init/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (c *ClusterConverter) installYurtManagerByHelm() error {
imageTagParts := strings.Split(parts[len(parts)-1], ":")
tag := imageTagParts[1]

cmd := exec.Command(helmPath, "install", "yurt-manager", yurtManagerChartPath, "--namespace", "kube-system", "--set", fmt.Sprintf("image.tag=%s", tag))
cmd := exec.Command(helmPath, "install", "yurt-manager", yurtManagerChartPath, "--namespace", "kube-system", "--set", fmt.Sprintf("image.tag=%s,initImage.tag=%s", tag, tag))
output, err := cmd.CombinedOutput()
if err != nil {
klog.Errorf("couldn't install yurt-manager, %v", err)
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/cmd/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ var (
yurtManagerImageFormat = "openyurt/yurt-manager:%s"
nodeServantImageFormat = "openyurt/node-servant:%s"
yurtIotDockImageFormat = "openyurt/yurt-iot-dock:%s"
CRDUpgraderImageFormat = "openyurt/crd-upgrader:%s"
)

func NewInitCMD(out io.Writer) *cobra.Command {
Expand Down Expand Up @@ -218,6 +219,7 @@ func (o *kindOptions) Config() *initializerConfig {
YurtManagerImage: fmt.Sprintf(yurtManagerImageFormat, o.OpenYurtVersion),
NodeServantImage: fmt.Sprintf(nodeServantImageFormat, o.OpenYurtVersion),
yurtIotDockImage: fmt.Sprintf(yurtIotDockImageFormat, o.OpenYurtVersion),
CRDUpgraderImage: fmt.Sprintf(CRDUpgraderImageFormat, o.OpenYurtVersion),
DisableDefaultCNI: o.DisableDefaultCNI,
}
}
Expand Down Expand Up @@ -261,6 +263,7 @@ type initializerConfig struct {
YurtManagerImage string
NodeServantImage string
yurtIotDockImage string
CRDUpgraderImage string
DisableDefaultCNI bool
}

Expand Down Expand Up @@ -501,6 +504,7 @@ func (ki *Initializer) prepareImages() error {
ki.YurtManagerImage,
ki.NodeServantImage,
ki.yurtIotDockImage,
ki.CRDUpgraderImage,
}, ki.CloudNodes); err != nil {
return err
}
Expand Down
Loading