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

Commit

Permalink
Merge pull request #56 from christopherhein/bug/54-repo-url
Browse files Browse the repository at this point in the history
Adding Code to Support AccountID and Templated Outputs
  • Loading branch information
Christopher Hein committed Aug 25, 2018
2 parents 2b52f3a + 4eedf27 commit b62fc1a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 5 deletions.
3 changes: 3 additions & 0 deletions cloudformation/ecrrepository.yaml
Expand Up @@ -31,3 +31,6 @@ Outputs:
RepositoryName:
Value: !Ref ECRRepository
Description: Name of the topic
RepositoryARN:
Value: !GetAtt ECRRepository.Arn
Description: ARN of the Repository
5 changes: 4 additions & 1 deletion cmd/aws-operator/main.go
Expand Up @@ -14,7 +14,7 @@ import (

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

// rootCmd represents the base command when called without any subcommands
rootCmd = &cobra.Command{
Expand Down Expand Up @@ -45,6 +45,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&resources, "resources", "", "s3bucket,dynamodb", "Comma delimited list of CRDs to deploy")
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")
rootCmd.PersistentFlags().StringVarP(&bucket, "bucket", "b", "aws-operator", "To configure the operator you need a base bucket to contain the resources")
rootCmd.PersistentFlags().StringVarP(&accountID, "account-id", "a", "", "AWS Account ID, this is used to configure outputs and operate on the proper account.")

viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
viper.BindPFlag("kubeconfig", rootCmd.PersistentFlags().Lookup("kubeconfig"))
Expand All @@ -54,6 +55,7 @@ func init() {
viper.BindPFlag("resources", rootCmd.PersistentFlags().Lookup("resources"))
viper.BindPFlag("clustername", rootCmd.PersistentFlags().Lookup("cluster-name"))
viper.BindPFlag("bucket", rootCmd.PersistentFlags().Lookup("bucket"))
viper.BindPFlag("accountid", rootCmd.PersistentFlags().Lookup("account-id"))
}

// initConfig reads in config file and ENV variables if set.
Expand Down Expand Up @@ -94,6 +96,7 @@ func getConfig() (*config.Config, error) {
Resources: resourcesList,
ClusterName: clusterName,
Bucket: bucket,
AccountID: accountID,
}

return config, nil
Expand Down
13 changes: 13 additions & 0 deletions models/ecrrepository.yaml
Expand Up @@ -53,3 +53,16 @@ spec:
the repository name. For more information, see Name Type.
structKey: RepositoryName
templateKey: RepositoryName
- key: repositoryARN
type: string
description: |
ARN for the Amazon ECR Repository
structKey: RepositoryARN
templateKey: RepositoryARN
- key: repositoryURL
type: string
description: |
URL for the Amazon ECR Repository
structKey: RepositoryURL
templatized: true
template: "{{.Config.AccountID}}.dkr.ecr.{{.Config.Region}}.amazonaws.com/{{.Obj.Name}}"
6 changes: 3 additions & 3 deletions models/s3bucket.yaml
Expand Up @@ -69,15 +69,15 @@ spec:
services:
- name: s3BucketSvc
type: ExternalName
externalName: "{{.Obj.Spec.BucketName}}.s3-{{.Config.Region}}.amazonaws.com"
externalName: "{{.Obj.Name}}.s3-{{.Config.Region}}.amazonaws.com"
ports:
- port: 443
configMap:
- name: s3BucketCM
data:
bucketName: "{{.Obj.Spec.BucketName}}"
bucketName: "{{.Obj.Name}}"
bucketARN: "{{.Obj.Output.BucketARN}}"
serviceName: "{{.Obj}}"
region: "{{.Config.Region}}"
bucketURL: "{{.Obj.Output.BucketName}}.s3-{{.Config.Region}}.amazonaws.com"
bucketURL: "{{.Obj.Name}}.s3-{{.Config.Region}}.amazonaws.com"

2 changes: 2 additions & 0 deletions pkg/apis/operator.aws/v1alpha1/ecrrepository.go
Expand Up @@ -28,6 +28,8 @@ type ECRRepositorySpec struct {
// ECRRepositoryOutput defines the output resource for ECRRepository
type ECRRepositoryOutput struct {
RepositoryName string `json:"repositoryName"`
RepositoryARN string `json:"repositoryARN"`
RepositoryURL string `json:"repositoryURL"`
}

// ECRRepositoryStatus holds the status of the Cloudformation template
Expand Down
1 change: 1 addition & 0 deletions pkg/config/types.go
Expand Up @@ -21,6 +21,7 @@ type Config struct {
Resources []string
ClusterName string
Bucket string
AccountID string
}

// LoggingConfig defines the attributes for the logger
Expand Down
3 changes: 3 additions & 0 deletions pkg/operator/ecrrepository/controller.go
Expand Up @@ -172,6 +172,9 @@ func updateStatus(config *config.Config, name string, namespace string, stackID
logger.WithError(err).Error("error getting outputs")
}
resourceCopy.Output.RepositoryName = outputs["RepositoryName"]
resourceCopy.Output.RepositoryARN = outputs["RepositoryARN"]
repositoryURL, _ := helpers.Templatize("{{.Config.AccountID}}.dkr.ecr.{{.Config.Region}}.amazonaws.com/{{.Obj.Name}}", helpers.Data{Obj: resourceCopy, Config: config})
resourceCopy.Output.RepositoryURL = repositoryURL
}

_, err = clientSet.ECRRepositories(namespace).Update(resourceCopy)
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/s3bucket/controller.go
Expand Up @@ -198,7 +198,7 @@ func syncAdditionalResources(config *config.Config, s *awsV1alpha1.S3Bucket) (er
resource = resource.DeepCopy()

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

Expand Down

0 comments on commit b62fc1a

Please sign in to comment.