Skip to content

Commit afad99f

Browse files
howardgaoroot
authored andcommitted
Support putting external images into the local registry of the kubevirtci cluster (#3801)
User can define an environment variable EXTRA_IMAGES that contains a list of external image urls separated by spaces. At the end of 'make cluster-up' target the EXTRA_IMAGES are processed by a script ./cluster-up/extra-images.sh so that for each image url, it pulls the image and then push the image into the local registry. Then when 'make cluster-sync' is invoked, it searches all external image urls in the generated yamls in _out/manifests/ and replaces them with corresponding urls in the local registry (registry:5000) Signed-off-by: Howard Gao <[email protected]>
1 parent 6d6517a commit afad99f

File tree

9 files changed

+73
-14
lines changed

9 files changed

+73
-14
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ docker-registry-cleanup: ## Clean up all cached images from docker registry. Acc
126126
publish: manifests push ## Generate a cdi-controller and operator manifests and push the built container images to the registry defined in DOCKER_PREFIX
127127

128128
manifests: ## Generate a cdi-controller and operator manifests in '_out/manifests/'. Accepts [make variables]\(#make-variables\) DOCKER_TAG, DOCKER_PREFIX, VERBOSITY, PULL_POLICY, CSV_VERSION, QUAY_REPOSITORY, QUAY_NAMESPACE
129-
${DO_BAZ} "DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} VERBOSITY=${VERBOSITY} PULL_POLICY=${PULL_POLICY} CR_NAME=${CR_NAME} CDI_NAMESPACE=${CDI_NAMESPACE} ./hack/build/build-manifests.sh"
129+
${DO_BAZ} "DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} VERBOSITY=${VERBOSITY} PULL_POLICY=${PULL_POLICY} CR_NAME=${CR_NAME} CDI_NAMESPACE=${CDI_NAMESPACE} EXTRA_IMAGES=\"${EXTRA_IMAGES}\" ./hack/build/build-manifests.sh"
130130

131131
release-description: ## Generate a release announcement detailing changes between 2 commits (typically tags). Expects 'RELREF' and 'PREREF' to be set
132132
./hack/build/release-description.sh ${RELREF} ${PREREF}
@@ -140,6 +140,7 @@ openshift-ci-image-push: ## Build and push the OpenShift CI build+test container
140140
##@ Local cluster management
141141
cluster-up: ## Start a default Kubernetes or Open Shift cluster. set KUBEVIRT_PROVIDER environment variable to either 'k8s-1.18' or 'os-3.11.0' to select the type of cluster. set KUBEVIRT_NUM_NODES to something higher than 1 to have more than one node.
142142
./cluster-up/up.sh
143+
./hack/extra-images.sh
143144

144145
cluster-down: ## Stop the cluster, doing a make cluster-down && make cluster-up will basically restart the cluster into an empty fresh state.
145146
./cluster-up/down.sh

hack/build/build-manifests.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ source "${script_dir}"/resource-generator.sh
3232

3333
mkdir -p "${MANIFEST_GENERATED_DIR}/"
3434

35+
# Update manifests to replace extra images with internal registry ones
36+
if [ -n "${EXTRA_IMAGES-}" ]; then
37+
for img in ${EXTRA_IMAGES}; do
38+
base_image_path="${img#*/}"
39+
local_img_url="registry:5000/${base_image_path}"
40+
if [ "$img" = "${EXTERNAL_IMAGE_MINIO}" ]; then
41+
EXTERNAL_IMAGE_MINIO=$local_img_url
42+
fi
43+
if [ "$img" = "${EXTERNAL_IMAGE_FAKEOVIRT}" ]; then
44+
EXTERNAL_IMAGE_FAKEOVIRT=$local_img_url
45+
fi
46+
done
47+
fi
48+
3549
#generate operator related manifests used to deploy cdi with operator-framework
3650
generateResourceManifest $generator $MANIFEST_GENERATED_DIR "operator" "everything" "operator-everything.yaml.in"
3751

hack/build/config.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ CDI_LOGO_PATH=${CDI_LOGO_PATH:-"assets/cdi_logo.png"}
6464
# oVirt populator image, by default it is the same as the importer image
6565
OVIRT_POPULATOR_IMAGE_NAME=${OVIRT_POPULATOR_IMAGE_NAME:-cdi-importer}
6666

67+
EXTERNAL_IMAGE_MINIO=${EXTERNAL_IMAGE_MINIO:-quay.io/kubevirt/minio:RELEASE.2024-10-02T17-50-41Z}
68+
EXTERNAL_IMAGE_FAKEOVIRT=${EXTERNAL_IMAGE_FAKEOVIRT:-quay.io/kubevirt/fakeovirt:v1.38.0}
69+
6770
function allPkgs() {
6871
ret=$(sed "s,kubevirt.io/containerized-data-importer,${CDI_DIR},g" <(go list ./pkg/... ./tools/... ./tests/... ./cmd/... | grep -v "pkg/client" | sort -u))
6972
echo "$ret"

hack/build/resource-generator.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ function populateResourceManifest() {
131131
-uploadproxy-image="${DOCKER_PREFIX}/${UPLOADPROXY_IMAGE_NAME}:${DOCKER_TAG}" \
132132
-uploadserver-image="${DOCKER_PREFIX}/${UPLOADSERVER_IMAGE_NAME}:${DOCKER_TAG}" \
133133
-ovirt-populator-image="${OVIRT_POPULATOR_IMAGE_NAME}" \
134+
-external-image-minio="${EXTERNAL_IMAGE_MINIO}" \
135+
-external-image-fakeovirt="${EXTERNAL_IMAGE_FAKEOVIRT}" \
134136
-verbosity="${VERBOSITY}" \
135137
-pull-policy="${PULL_POLICY}" \
136138
-cr-name="${CR_NAME}" \
@@ -152,6 +154,8 @@ function populateResourceManifest() {
152154
-apiserver-image="{{ apiserver_image }}" \
153155
-uploadproxy-image="{{ uploadproxy_image }}" \
154156
-uploadserver-image="{{ uploadserver_image }}" \
157+
-external-image-minio="{{ external_image_minio }}" \
158+
-external-image-fakeovirt="{{ external_image_fakeovirt }}" \
155159
-verbosity="${VERBOSITY}" \
156160
-pull-policy="{{ pull_policy }}" \
157161
-namespace="{{ cdi_namespace }}" \

hack/extra-images.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
script_dir="$(cd "$(dirname "$0")" && pwd -P)"
6+
source "${script_dir}"/build/common.sh
7+
source ./cluster-up/hack/common.sh
8+
source ./cluster-up/cluster/${KUBEVIRT_PROVIDER}/provider.sh
9+
10+
cri_bin=$1
11+
if [ -z $cri_bin ]; then
12+
cri_bin=$CDI_CRI
13+
fi
14+
15+
if [ -n "${EXTRA_IMAGES}" ]; then
16+
registry_port=$(_port registry)
17+
for img in ${EXTRA_IMAGES}; do
18+
base_image_path="${img#*/}"
19+
local_img_url="localhost:${registry_port}/${base_image_path}"
20+
$cri_bin pull $img
21+
$cri_bin tag $img $local_img_url
22+
$cri_bin push $local_img_url
23+
done
24+
fi

manifests/templates/file-host.yaml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ spec:
6060
initialDelaySeconds: 20
6161
periodSeconds: 20
6262
- name: s3
63-
image: quay.io/kubevirt/minio:RELEASE.2024-10-02T17-50-41Z
63+
image: {{ .ExternalImageMinio }}
6464
imagePullPolicy: {{ .PullPolicy }}
6565
env:
6666
- name: MINIO_ACCESS_KEY

manifests/templates/imageio.yaml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ spec:
4848
add-ticket myticket.json && tail -n+1 -f /var/log/ovirt-imageio/daemon.log
4949
- name: fakeovirt
5050
# Docker file: https://github.com/machacekondra/fakeovirt
51-
image: quay.io/kubevirt/fakeovirt:v1.38.0
51+
image: {{ .ExternalImageFakeovirt }}
5252
imagePullPolicy: {{ .PullPolicy }}
5353
ports:
5454
- containerPort: 12346

pkg/operator/resources/namespaced/factory.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ type FactoryArgs struct {
4040
APIServerImage string `required:"true" envconfig:"apiserver_image"`
4141
UploadProxyImage string `required:"true" split_words:"true"`
4242
UploadServerImage string `required:"true" split_words:"true"`
43+
ExternalImageMinio string `split_words:"true"`
44+
ExternalImageFakeovirt string `split_words:"true"`
4345
Verbosity string `required:"true"`
4446
PullPolicy string `required:"true" split_words:"true"`
4547
ImagePullSecrets []corev1.LocalObjectReference

tools/manifest-generator/manifest-generator.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ type templateData struct {
4141
APIServerImage string
4242
UploadProxyImage string
4343
UploadServerImage string
44+
ExternalImageMinio string
45+
ExternalImageFakeovirt string
4446
Verbosity string
4547
PullPolicy string
4648
CrName string
@@ -62,6 +64,8 @@ var (
6264
apiServerImage = flag.String("apiserver-image", "", "")
6365
uploadProxyImage = flag.String("uploadproxy-image", "", "")
6466
uploadServerImage = flag.String("uploadserver-image", "", "")
67+
externalImageMinio = flag.String("external-image-minio", "", "")
68+
externalImageFakeovirt = flag.String("external-image-fakeovirt", "", "")
6569
verbosity = flag.String("verbosity", "1", "")
6670
pullPolicy = flag.String("pull-policy", "", "")
6771
crName = flag.String("cr-name", "", "")
@@ -76,6 +80,9 @@ func main() {
7680

7781
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
7882
klog.InitFlags(klogFlags)
83+
84+
klog.Info("========Generator", "templFile", templFile)
85+
7986
flag.CommandLine.VisitAll(func(f1 *flag.Flag) {
8087
f2 := klogFlags.Lookup(f1.Name)
8188
if f2 != nil {
@@ -108,6 +115,8 @@ func generateFromFile(templFile string) {
108115
APIServerImage: *apiServerImage,
109116
UploadProxyImage: *uploadProxyImage,
110117
UploadServerImage: *uploadServerImage,
118+
ExternalImageMinio: *externalImageMinio,
119+
ExternalImageFakeovirt: *externalImageFakeovirt,
111120
PullPolicy: *pullPolicy,
112121
CrName: *crName,
113122
Namespace: *namespace,
@@ -205,17 +214,19 @@ func getClusterResources(codeGroup string) ([]client.Object, error) {
205214

206215
func getNamespacedResources(codeGroup string) ([]client.Object, error) {
207216
args := &cdinamespaced.FactoryArgs{
208-
Verbosity: *verbosity,
209-
OperatorVersion: *operatorVersion,
210-
ControllerImage: *controllerImage,
211-
ImporterImage: *importerImage,
212-
ClonerImage: *clonerImage,
213-
OvirtPopulatorImage: *ovirtPopulatorImage,
214-
APIServerImage: *apiServerImage,
215-
UploadProxyImage: *uploadProxyImage,
216-
UploadServerImage: *uploadServerImage,
217-
PullPolicy: *pullPolicy,
218-
Namespace: *namespace,
217+
Verbosity: *verbosity,
218+
OperatorVersion: *operatorVersion,
219+
ControllerImage: *controllerImage,
220+
ImporterImage: *importerImage,
221+
ClonerImage: *clonerImage,
222+
OvirtPopulatorImage: *ovirtPopulatorImage,
223+
APIServerImage: *apiServerImage,
224+
UploadProxyImage: *uploadProxyImage,
225+
UploadServerImage: *uploadServerImage,
226+
ExternalImageMinio: *externalImageMinio,
227+
ExternalImageFakeovirt: *externalImageFakeovirt,
228+
PullPolicy: *pullPolicy,
229+
Namespace: *namespace,
219230
}
220231

221232
return cdinamespaced.CreateResourceGroup(codeGroup, args)

0 commit comments

Comments
 (0)