Skip to content

Commit 8f02d77

Browse files
authored
refactoring --image-repository arg so it can be used across cmds (#282)
Issue #, if available: - Fixes: aws-controllers-k8s/community#1154 - Fixes: aws-controllers-k8s/community#780 Description of changes: - refactoring --image-repository arg so it can be used across cmds - removing redundant steps in the olm-create-bundle script that is now handled in code/kustomize directly - referencing new template args in CSV tpl to keep it consistent with the deployment By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. Signed-off-by: Adam D. Cornett <[email protected]>
1 parent 76bb8df commit 8f02d77

File tree

6 files changed

+36
-62
lines changed

6 files changed

+36
-62
lines changed

cmd/ack-generate/command/olm.go

-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ func init() {
5858
olmCmd.PersistentFlags().BoolVar(
5959
&optDisableCommonKeywords, "no-common-keywords", false, "does not include common keywords in the rendered cluster service version",
6060
)
61-
olmCmd.PersistentFlags().StringVar(
62-
&optImageRepository, "image-repository", "", "the Docker image repository that stores the ACK service controller. Default: 'public.ecr.aws/aws-controllers-k8s/$service-controller'",
63-
)
6461

6562
rootCmd.AddCommand(olmCmd)
6663
}

cmd/ack-generate/command/release.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ import (
2626
ackmetadata "github.com/aws-controllers-k8s/code-generator/pkg/metadata"
2727
)
2828

29-
var (
30-
optReleaseOutputPath string
31-
optImageRepository string
32-
)
29+
var optReleaseOutputPath string
3330

3431
var releaseCmd = &cobra.Command{
3532
Use: "release <service> <release_version>",
@@ -38,9 +35,6 @@ var releaseCmd = &cobra.Command{
3835
}
3936

4037
func init() {
41-
releaseCmd.PersistentFlags().StringVar(
42-
&optImageRepository, "image-repository", "", "the Docker image repository to use in release artifacts. Defaults to 'public.ecr.aws/aws-controllers-k8s/$service-controller'",
43-
)
4438
releaseCmd.PersistentFlags().StringVarP(
4539
&optReleaseOutputPath, "output", "o", "", "path to root directory to create generated files. Defaults to "+optServicesDir+"/$service",
4640
)

cmd/ack-generate/command/root.go

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var (
4444
optMetadataConfigPath string
4545
optOutputPath string
4646
optServiceAccountName string
47+
optImageRepository string
4748
)
4849

4950
var rootCmd = &cobra.Command{
@@ -125,6 +126,9 @@ func init() {
125126
rootCmd.PersistentFlags().StringVar(
126127
&optServiceAccountName, "service-account-name", "", "The name of the ServiceAccount used for ACK service controller",
127128
)
129+
rootCmd.PersistentFlags().StringVar(
130+
&optImageRepository, "image-repository", "", "the Docker image repository to use in release artifacts. Defaults to 'public.ecr.aws/aws-controllers-k8s/$service-controller'",
131+
)
128132
}
129133

130134
// Execute adds all child commands to the root command and sets flags

scripts/build-controller-release.sh

+3
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ if [[ $ACK_GENERATE_OLM == "true" ]]; then
249249
if [ -n "$ACK_GENERATE_CONFIG_PATH" ]; then
250250
ag_olm_args="$ag_olm_args --generator-config-path $ACK_GENERATE_CONFIG_PATH"
251251
fi
252+
if [ -n "$ACK_GENERATE_IMAGE_REPOSITORY" ]; then
253+
ag_olm_args="$ag_olm_args --image-repository $ACK_GENERATE_IMAGE_REPOSITORY"
254+
fi
252255

253256
$ACK_GENERATE_BIN_PATH olm $ag_olm_args
254257
$SCRIPTS_DIR/olm-create-bundle.sh "$SERVICE" "$RELEASE_VERSION"

scripts/olm-create-bundle.sh

+27-51
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
99
ROOT_DIR="$SCRIPTS_DIR/.."
1010
BUILD_DIR="$ROOT_DIR/build"
1111
DEFAULT_BUNDLE_CHANNEL="alpha"
12-
DEFAULT_SERVICE_CONTROLLER_CONTAINER_REPOSITORY="public.ecr.aws/aws-controllers-k8s"
1312
PRESERVE=${PRESERVE:-"false"}
1413

1514
export DOCKER_BUILDKIT=${DOCKER_BUILDKIT:-1}
@@ -38,38 +37,33 @@ Usage:
3837
's3' 'sns' or 'sqs'. <version> should be the semver of the OLM bundle.
3938
4039
Environment variables:
41-
BUNDLE_DEFAULT_CHANNEL The default channel to publish the OLM bundle to.
42-
Default: $DEFAULT_BUNDLE_CHANNEL
43-
BUNDLE_VERSION The semantic version of the bundle should it need
44-
to differ from the version of the controller which is
45-
passed into the script. Optional. If unset, this
46-
value will match that passed in by the user as the
47-
<version> parameter (i.e. the controller version)
48-
BUNDLE_CHANNELS A comma-separated list of channels the bundle belongs
49-
to (e.g. \"alpha,beta\").
50-
Default: $DEFAULT_BUNDLE_CHANNEL
51-
BUNDLE_OUTPUT_PATH: Specify a path for the OLM bundle to output to.
52-
Default: {SERVICE_CONTROLLER_SOURCE_PATH}/olm
53-
AWS_SERVICE_DOCKER_IMG: Specify the docker image for the AWS service.
54-
This should include the registry, namespace,
55-
image name, and tag. Takes precedence over
56-
SERVICE_CONTROLLER_CONTAINER_REPOSITORY
57-
SERVICE_CONTROLLER_SOURCE_PATH: Path to the service controller source code
58-
repository.
59-
Default: ../{SERVICE}-controller
60-
SERVICE_CONTROLLER_CONTAINER_REPOSITORY The container repository where the controller exists.
61-
This should include the registry, namespace, and
62-
image name.
63-
Default: $DEFAULT_SERVICE_CONTROLLER_CONTAINER_REPOSITORY
64-
TMP_DIR Directory where kustomize assets will be temporarily
65-
copied before they are modified and passed to bundle
66-
generation logic.
67-
Default: $BUILD_DIR/tmp-olm-{RANDOMSTRING}
68-
PRESERVE: Preserves modified kustomize configs for
69-
inspection. (<true|false>)
70-
Default: false
71-
BUNDLE_GENERATE_EXTRA_ARGS Extra arguments to pass into the command
72-
'operator-sdk generate bundle'.
40+
BUNDLE_DEFAULT_CHANNEL The default channel to publish the OLM bundle to.
41+
Default: $DEFAULT_BUNDLE_CHANNEL
42+
BUNDLE_VERSION The semantic version of the bundle should it need
43+
to differ from the version of the controller which is
44+
passed into the script. Optional. If unset, this
45+
value will match that passed in by the user as the
46+
<version> parameter (i.e. the controller version)
47+
BUNDLE_CHANNELS A comma-separated list of channels the bundle belongs
48+
to (e.g. \"alpha,beta\").
49+
Default: $DEFAULT_BUNDLE_CHANNEL
50+
BUNDLE_OUTPUT_PATH: Specify a path for the OLM bundle to output to.
51+
Default: {SERVICE_CONTROLLER_SOURCE_PATH}/olm
52+
ACK_GENERATE_IMAGE_REPOSITORY: Specify a Docker image repository to use
53+
for release artifacts
54+
Default: public.ecr.aws/aws-controllers-k8s/{SERVICE}-controller
55+
SERVICE_CONTROLLER_SOURCE_PATH: Path to the service controller source code
56+
repository.
57+
Default: ../{SERVICE}-controller
58+
TMP_DIR Directory where kustomize assets will be temporarily
59+
copied before they are modified and passed to bundle
60+
generation logic.
61+
Default: $BUILD_DIR/tmp-olm-{RANDOMSTRING}
62+
PRESERVE: Preserves modified kustomize configs for
63+
inspection. (<true|false>)
64+
Default: false
65+
BUNDLE_GENERATE_EXTRA_ARGS Extra arguments to pass into the command
66+
'operator-sdk generate bundle'.
7367
"
7468

7569
if [ $# -ne 2 ]; then
@@ -103,29 +97,11 @@ if [[ ! -d $SERVICE_CONTROLLER_SOURCE_PATH ]]; then
10397
exit 1
10498
fi
10599

106-
# Set controller image.
107-
if [ -n "$AWS_SERVICE_DOCKER_IMG" ] && [ -n "$SERVICE_CONTROLLER_CONTAINER_REPOSITORY" ] ; then
108-
# It's possible to set the repository (i.e. everything except the tag) as well as the
109-
# entire path including the tag using AWS_SERVIC_DOCKER_IMG. If the latter is set, it
110-
# will take precedence, so inform the user that this will happen in case the usage of
111-
# each configurable is unclear before runtime.
112-
echo "both AWS_SERVICE_DOCKER_IMG and SERVICE_CONTROLLER_CONTAINER REPOSITORY are set."
113-
echo "AWS_SERVICE_DOCKER_IMG is expected to be more complete and will take precedence."
114-
echo "Ignoring SERVICE_CONTROLLER_CONTAINER_REPOSITORY."
115-
fi
116-
117-
SERVICE_CONTROLLER_CONTAINER_REPOSITORY=${SERVICE_CONTROLLER_CONTAINER_REPOSITORY:-$DEFAULT_SERVICE_CONTROLLER_CONTAINER_REPOSITORY}
118-
DEFAULT_AWS_SERVICE_DOCKER_IMAGE="$SERVICE_CONTROLLER_CONTAINER_REPOSITORY/$SERVICE-controller:v$VERSION"
119-
AWS_SERVICE_DOCKER_IMG=${AWS_SERVICE_DOCKER_IMG:-$DEFAULT_AWS_SERVICE_DOCKER_IMAGE}
120-
121100
trap "clean_up" EXIT
122101

123102
# prepare the temporary config dir
124103
mkdir -p $TMP_DIR
125104
cp -a $SERVICE_CONTROLLER_SOURCE_PATH/config $TMP_DIR
126-
pushd $tmp_kustomize_config_dir/controller 1>/dev/null
127-
kustomize edit set image controller="$AWS_SERVICE_DOCKER_IMG"
128-
popd 1>/dev/null
129105

130106
# remove crd/common from bases to prevent inclusion of AdoptedResource CRD from being generated in the bundle directory
131107
sed -i.orig '/^bases:$/d' $tmp_kustomize_config_dir/crd/kustomization.yaml

templates/config/manifests/bases/clusterserviceversion.yaml.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
capabilities: {{.Annotations.CapabilityLevel}}
88
operatorframework.io/suggested-namespace: "ack-system"
99
repository: {{.Annotations.Repository}}
10-
containerImage: {{.Annotations.ContainerImage}}/{{.ServicePackageName}}-controller:v{{.Version}}
10+
containerImage: {{ .ImageRepository }}:{{ .ReleaseVersion }}
1111
description: {{.Annotations.ShortDescription}}
1212
createdAt: {{.CreatedAt}}
1313
support: {{.Annotations.Support}}

0 commit comments

Comments
 (0)