Skip to content
This repository was archived by the owner on Nov 7, 2019. It is now read-only.

Commit b62fc1a

Browse files
author
Christopher Hein
authored
Merge pull request #56 from christopherhein/bug/54-repo-url
Adding Code to Support AccountID and Templated Outputs
2 parents 2b52f3a + 4eedf27 commit b62fc1a

File tree

8 files changed

+30
-5
lines changed

8 files changed

+30
-5
lines changed

cloudformation/ecrrepository.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ Outputs:
3131
RepositoryName:
3232
Value: !Ref ECRRepository
3333
Description: Name of the topic
34+
RepositoryARN:
35+
Value: !GetAtt ECRRepository.Arn
36+
Description: ARN of the Repository

cmd/aws-operator/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
var (
1616
// cfgFile, kubeConfig, awsRegion all help support passed in flags into the server
17-
cfgFile, kubeconfig, awsRegion, logLevel, logFile, resources, clusterName, bucket string
17+
cfgFile, kubeconfig, awsRegion, logLevel, logFile, resources, clusterName, bucket, accountID string
1818

1919
// rootCmd represents the base command when called without any subcommands
2020
rootCmd = &cobra.Command{
@@ -45,6 +45,7 @@ func init() {
4545
rootCmd.PersistentFlags().StringVarP(&resources, "resources", "", "s3bucket,dynamodb", "Comma delimited list of CRDs to deploy")
4646
rootCmd.PersistentFlags().StringVarP(&clusterName, "cluster-name", "i", "aws-operator", "Cluster name for the Application to run as, used to label the Cloudformation templated to avoid conflict")
4747
rootCmd.PersistentFlags().StringVarP(&bucket, "bucket", "b", "aws-operator", "To configure the operator you need a base bucket to contain the resources")
48+
rootCmd.PersistentFlags().StringVarP(&accountID, "account-id", "a", "", "AWS Account ID, this is used to configure outputs and operate on the proper account.")
4849

4950
viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
5051
viper.BindPFlag("kubeconfig", rootCmd.PersistentFlags().Lookup("kubeconfig"))
@@ -54,6 +55,7 @@ func init() {
5455
viper.BindPFlag("resources", rootCmd.PersistentFlags().Lookup("resources"))
5556
viper.BindPFlag("clustername", rootCmd.PersistentFlags().Lookup("cluster-name"))
5657
viper.BindPFlag("bucket", rootCmd.PersistentFlags().Lookup("bucket"))
58+
viper.BindPFlag("accountid", rootCmd.PersistentFlags().Lookup("account-id"))
5759
}
5860

5961
// initConfig reads in config file and ENV variables if set.
@@ -94,6 +96,7 @@ func getConfig() (*config.Config, error) {
9496
Resources: resourcesList,
9597
ClusterName: clusterName,
9698
Bucket: bucket,
99+
AccountID: accountID,
97100
}
98101

99102
return config, nil

models/ecrrepository.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,16 @@ spec:
5353
the repository name. For more information, see Name Type.
5454
structKey: RepositoryName
5555
templateKey: RepositoryName
56+
- key: repositoryARN
57+
type: string
58+
description: |
59+
ARN for the Amazon ECR Repository
60+
structKey: RepositoryARN
61+
templateKey: RepositoryARN
62+
- key: repositoryURL
63+
type: string
64+
description: |
65+
URL for the Amazon ECR Repository
66+
structKey: RepositoryURL
67+
templatized: true
68+
template: "{{.Config.AccountID}}.dkr.ecr.{{.Config.Region}}.amazonaws.com/{{.Obj.Name}}"

models/s3bucket.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ spec:
6969
services:
7070
- name: s3BucketSvc
7171
type: ExternalName
72-
externalName: "{{.Obj.Spec.BucketName}}.s3-{{.Config.Region}}.amazonaws.com"
72+
externalName: "{{.Obj.Name}}.s3-{{.Config.Region}}.amazonaws.com"
7373
ports:
7474
- port: 443
7575
configMap:
7676
- name: s3BucketCM
7777
data:
78-
bucketName: "{{.Obj.Spec.BucketName}}"
78+
bucketName: "{{.Obj.Name}}"
7979
bucketARN: "{{.Obj.Output.BucketARN}}"
8080
serviceName: "{{.Obj}}"
8181
region: "{{.Config.Region}}"
82-
bucketURL: "{{.Obj.Output.BucketName}}.s3-{{.Config.Region}}.amazonaws.com"
82+
bucketURL: "{{.Obj.Name}}.s3-{{.Config.Region}}.amazonaws.com"
8383

pkg/apis/operator.aws/v1alpha1/ecrrepository.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type ECRRepositorySpec struct {
2828
// ECRRepositoryOutput defines the output resource for ECRRepository
2929
type ECRRepositoryOutput struct {
3030
RepositoryName string `json:"repositoryName"`
31+
RepositoryARN string `json:"repositoryARN"`
32+
RepositoryURL string `json:"repositoryURL"`
3133
}
3234

3335
// ECRRepositoryStatus holds the status of the Cloudformation template

pkg/config/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Config struct {
2121
Resources []string
2222
ClusterName string
2323
Bucket string
24+
AccountID string
2425
}
2526

2627
// LoggingConfig defines the attributes for the logger

pkg/operator/ecrrepository/controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ func updateStatus(config *config.Config, name string, namespace string, stackID
172172
logger.WithError(err).Error("error getting outputs")
173173
}
174174
resourceCopy.Output.RepositoryName = outputs["RepositoryName"]
175+
resourceCopy.Output.RepositoryARN = outputs["RepositoryARN"]
176+
repositoryURL, _ := helpers.Templatize("{{.Config.AccountID}}.dkr.ecr.{{.Config.Region}}.amazonaws.com/{{.Obj.Name}}", helpers.Data{Obj: resourceCopy, Config: config})
177+
resourceCopy.Output.RepositoryURL = repositoryURL
175178
}
176179

177180
_, err = clientSet.ECRRepositories(namespace).Update(resourceCopy)

pkg/operator/s3bucket/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func syncAdditionalResources(config *config.Config, s *awsV1alpha1.S3Bucket) (er
198198
resource = resource.DeepCopy()
199199

200200
services := []string{}
201-
s3BucketSvc := helpers.CreateExternalNameService(config, s, s.Name, s.Namespace, "{{.Obj.Spec.BucketName}}.s3-{{.Config.Region}}.amazonaws.com", 443)
201+
s3BucketSvc := helpers.CreateExternalNameService(config, s, s.Name, s.Namespace, "{{.Obj.Name}}.s3-{{.Config.Region}}.amazonaws.com", 443)
202202
services = append(services, s3BucketSvc)
203203
resource.AdditionalResources.Services = services
204204

0 commit comments

Comments
 (0)