Skip to content

Commit 4c88d33

Browse files
Add release image to Kustomization (#277)
Issue #, if available: aws-controllers-k8s/community#1076 Description of changes: Adds the `config/controller/kustomization.yaml` file to the release part of the build, so that we can inject the release version and URL to the controller image path. Example of new `kustomization.yaml` (for S3): ```yaml resources: - deployment.yaml - service.yaml apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization images: - name: controller newName: public.ecr.aws/aws-controllers-k8s/s3-controller newTag: v0.0.11 ``` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 3a50ed4 commit 4c88d33

File tree

7 files changed

+40
-20
lines changed

7 files changed

+40
-20
lines changed

cmd/ack-generate/command/olm.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ 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+
)
6164

6265
rootCmd.AddCommand(olmCmd)
6366
}
@@ -75,6 +78,9 @@ func generateOLMAssets(cmd *cobra.Command, args []string) error {
7578
if optOutputPath == "" {
7679
optOutputPath = filepath.Join(optServicesDir, svcAlias)
7780
}
81+
if optImageRepository == "" {
82+
optImageRepository = fmt.Sprintf("public.ecr.aws/aws-controllers-k8s/%s-controller", svcAlias)
83+
}
7884

7985
version := args[1]
8086

@@ -119,7 +125,7 @@ func generateOLMAssets(cmd *cobra.Command, args []string) error {
119125
}
120126

121127
// generate templates
122-
ts, err := olmgenerate.BundleAssets(m, commonMeta, svcConf, version, optTemplateDirs)
128+
ts, err := olmgenerate.BundleAssets(m, commonMeta, svcConf, version, optImageRepository, optTemplateDirs)
123129
if err != nil {
124130
return err
125131
}

pkg/generate/ack/controller.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ var (
3030
controllerConfigTemplatePaths = []string{
3131
"config/controller/deployment.yaml.tpl",
3232
"config/controller/service.yaml.tpl",
33-
"config/controller/kustomization.yaml.tpl",
3433
"config/default/kustomization.yaml.tpl",
3534
"config/rbac/cluster-role-binding.yaml.tpl",
3635
"config/rbac/role-reader.yaml.tpl",
@@ -41,7 +40,6 @@ var (
4140
"config/overlays/namespaced/kustomization.yaml.tpl",
4241
}
4342
controllerIncludePaths = []string{
44-
"config/controller/kustomization_def.yaml.tpl",
4543
"boilerplate.go.tpl",
4644
"pkg/resource/references_read_referenced_resource.go.tpl",
4745
"pkg/resource/sdk_find_read_one.go.tpl",

pkg/generate/ack/release.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
var (
2626
releaseTemplatePaths = []string{
27+
"config/controller/kustomization.yaml.tpl",
2728
"helm/templates/cluster-role-binding.yaml.tpl",
2829
"helm/Chart.yaml.tpl",
2930
"helm/values.yaml.tpl",
@@ -33,8 +34,10 @@ var (
3334
"helm/templates/role-writer.yaml.tpl",
3435
"helm/templates/_controller-role-kind-patch.yaml.tpl",
3536
}
36-
releaseIncludePaths = []string{}
37-
releaseCopyPaths = []string{
37+
releaseIncludePaths = []string{
38+
"config/controller/kustomization_def.yaml.tpl",
39+
}
40+
releaseCopyPaths = []string{
3841
"helm/templates/_helpers.tpl",
3942
"helm/templates/deployment.yaml",
4043
"helm/templates/metrics-service.yaml",
@@ -73,9 +76,11 @@ func Release(
7376
metaVars := m.MetaVars()
7477
releaseVars := &templateReleaseVars{
7578
metaVars,
79+
ImageReleaseVars{
80+
ReleaseVersion: releaseVersion,
81+
ImageRepository: imageRepository,
82+
},
7683
metadata,
77-
releaseVersion,
78-
imageRepository,
7984
serviceAccountName,
8085
}
8186
for _, path := range releaseTemplatePaths {
@@ -88,17 +93,21 @@ func Release(
8893
return ts, nil
8994
}
9095

91-
// templateReleaseVars contains template variables for the template that
92-
// outputs Go code for a release artifact
93-
type templateReleaseVars struct {
94-
templateset.MetaVars
95-
Metadata *ackmetadata.ServiceMetadata
96+
type ImageReleaseVars struct {
9697
// ReleaseVersion is the semver release tag (or Git SHA1 commit) that is
9798
// used for the binary image artifacts and Helm release version
9899
ReleaseVersion string
99100
// ImageRepository is the Docker image repository to inject into the Helm
100101
// values template
101102
ImageRepository string
103+
}
104+
105+
// templateReleaseVars contains template variables for the template that
106+
// outputs Go code for a release artifact
107+
type templateReleaseVars struct {
108+
templateset.MetaVars
109+
ImageReleaseVars
110+
Metadata *ackmetadata.ServiceMetadata
102111
// ServiceAccountName is the name of the ServiceAccount used in the Helm chart
103112
ServiceAccountName string
104113
}

pkg/generate/olm/olm.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
ttpl "text/template"
77
"time"
88

9+
ackgenerate "github.com/aws-controllers-k8s/code-generator/pkg/generate/ack"
910
"github.com/aws-controllers-k8s/code-generator/pkg/generate/templateset"
1011
ackmodel "github.com/aws-controllers-k8s/code-generator/pkg/model"
1112
opsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
@@ -41,7 +42,8 @@ func BundleAssets(
4142
m *ackmodel.Model,
4243
commonMeta CommonMetadata,
4344
serviceConfig ServiceConfig,
44-
vers string,
45+
releaseVersion string,
46+
imageRepository string,
4547
templateBasePaths []string,
4648
) (*templateset.TemplateSet, error) {
4749

@@ -57,8 +59,13 @@ func BundleAssets(
5759
return nil, err
5860
}
5961

62+
olmVersion := strings.TrimLeft(releaseVersion, "v")
6063
olmVars := templateOLMVars{
61-
vers,
64+
ackgenerate.ImageReleaseVars{
65+
ReleaseVersion: releaseVersion,
66+
ImageRepository: imageRepository,
67+
},
68+
olmVersion,
6269
time.Now().Format("2006-01-02 15:04:05"),
6370
m.MetaVars(),
6471
commonMeta,
@@ -88,6 +95,7 @@ func BundleAssets(
8895
}
8996

9097
type templateOLMVars struct {
98+
ackgenerate.ImageReleaseVars
9199
Version string
92100
CreatedAt string
93101
templateset.MetaVars

scripts/build-controller-release.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,13 @@ if [[ $ACK_GENERATE_OLM == "true" ]]; then
243243
DEFAULT_ACK_GENERATE_OLMCONFIG_PATH="$SERVICE_CONTROLLER_SOURCE_PATH/olm/olmconfig.yaml"
244244
ACK_GENERATE_OLMCONFIG_PATH=${ACK_GENERATE_OLMCONFIG_PATH:-$DEFAULT_ACK_GENERATE_OLMCONFIG_PATH}
245245

246-
olm_version=$(echo $RELEASE_VERSION | tr -d "v")
247-
ag_olm_args="$SERVICE $olm_version -o $SERVICE_CONTROLLER_SOURCE_PATH --template-dirs $TEMPLATES_DIR --olm-config $ACK_GENERATE_OLMCONFIG_PATH --aws-sdk-go-version $AWS_SDK_GO_VERSION"
246+
ag_olm_args="$SERVICE $RELEASE_VERSION -o $SERVICE_CONTROLLER_SOURCE_PATH --template-dirs $TEMPLATES_DIR --olm-config $ACK_GENERATE_OLMCONFIG_PATH --aws-sdk-go-version $AWS_SDK_GO_VERSION"
248247

249248
if [ -n "$ACK_GENERATE_CONFIG_PATH" ]; then
250249
ag_olm_args="$ag_olm_args --generator-config-path $ACK_GENERATE_CONFIG_PATH"
251250
fi
252251

253252
$ACK_GENERATE_BIN_PATH olm $ag_olm_args
254-
$SCRIPTS_DIR/olm-create-bundle.sh "$SERVICE" "$olm_version"
253+
$SCRIPTS_DIR/olm-create-bundle.sh "$SERVICE" "$RELEASE_VERSION"
255254

256255
fi

scripts/olm-create-bundle.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Usage:
3535
$(basename "$0") <service> <version>
3636
3737
<service> should be an AWS service API aliases that you wish to build -- e.g.
38-
's3' 'sns' or 'sqs'
38+
's3' 'sns' or 'sqs'. <version> should be the semver of the OLM bundle.
3939
4040
Environment variables:
4141
BUNDLE_DEFAULT_CHANNEL The default channel to publish the OLM bundle to.

templates/config/controller/kustomization_def.yaml.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ apiVersion: kustomize.config.k8s.io/v1beta1
66
kind: Kustomization
77
images:
88
- name: controller
9-
newName: ack-{{ .ServicePackageName }}-controller
10-
newTag: latest
9+
newName: {{ .ImageRepository }}
10+
newTag: {{ .ReleaseVersion }}
1111
{{end}}

0 commit comments

Comments
 (0)