diff --git a/cloudformation/elasticache.yaml b/cloudformation/elasticache.yaml new file mode 100644 index 000000000..4291664de --- /dev/null +++ b/cloudformation/elasticache.yaml @@ -0,0 +1,160 @@ +AWSTemplateFormatVersion: "2010-09-09" +Description: 'AWS Operator - Amazon Elasticache Cluster' +Parameters: + Namespace: + Description: >- + This is the namespace for the Kubernetes object. + Type: String + ResourceVersion: + Type: String + Description: >- + This is the resource version for the Kubernetes object. + ResourceName: + Description: >- + This is the resource name for the Kubernetes object + Type: String + AutoMinorVersionUpgrade: + Description: >- + Indicates that minor engine upgrades will be applied automatically to the cache cluster during the maintenance window. + Type: String + Default: false + AZMode: + Description: >- + For Memcached cache clusters, indicates whether the nodes are created in a single Availability Zone or across multiple Availability Zones in the cluster's region. + Type: String + CacheNodeType: + Description: >- + The compute and memory capacity of nodes in a cache cluster. + https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/CacheNodes.SupportedTypes.html + Type: String + Default: cache.m5.large + CacheParameterGroupName: + Description: >- + The name of the cache parameter group that is associated with this cache cluster. + Type: String + CacheSubnetGroupName: + Description: >- + The cache subnet group that you associate with a cache cluster. + "Required: Conditional. If you specified the VpcSecurityGroupIds property, you must specify this property." + Type: String + ClusterName: + Description: >- + This is the cluster name for the operator + Type: String + Engine: + Description: >- + The name of the cache engine to be used for this cache cluster, such as memcached or redis. + Type: String + Default: "redis" + EngineVersion: + Description: >- + The version of the cache engine to be used for this cluster. + Type: String + Default: "5.0.0" + NotificationTopicArn: + Description: >- + The Amazon Resource Name (ARN) of the Amazon Simple Notification Service (SNS) topic to which notifications will be sent. + Type: String + NumCacheNodes: + Description: >- + The number of cache nodes that the cache cluster should have. + Type: Number + Default: "1" + Port: + Description: >- + The port number on which each of the cache nodes will accept connections. + Type: Number + PreferredMaintenanceWindow: + Description: >- + The weekly time range (in UTC) during which system maintenance can occur. + Type: String + Default: mon:05:00-mon:09:00 + PreferredAvailabilityZone: + Description: >- + The Amazon EC2 Availability Zone in which the cache cluster is created. + Type: String + PreferredAvailabilityZones: + Description: >- + For Memcached cache clusters, the list of Availability Zones in which cache nodes are created. The number of Availability Zones listed must equal the number of cache nodes. For example, if you want to create three nodes in two different Availability Zones, you can specify ["us-east-1a", "us-east-1a", "us-east-1b"], which would create two nodes in us-east-1a and one node in us-east-1b. + Type: CommaDelimitedList + SnapshotWindow: + Description: >- + For Redis cache clusters, the daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your node group. For example, you can specify 05:00-09:00. + Type: String + Default: "05:00-09:00" + VpcSecurityGroupIds: + Description: >- + A list of VPC security group IDs. If your cache cluster isn't in a VPC, specify the CacheSecurityGroupNames property instead. + Type: CommaDelimitedList +Conditions: + IsRedis: + !Equals [!Ref Engine, "redis"] + IsMemcached: + !Equals [!Ref Engine, "memcached"] + HasAZMode: + !Not [!Equals [!Ref AZMode, ""]] + HasPreferredAvailabilityZones: + !Not [!Equals [!Select [0, !Ref PreferredAvailabilityZones], ""]] + HasPreferredAvailabilityZone: + !Not [!Equals [!Ref PreferredAvailabilityZone, ""]] + HasVpcSecurityGroupIds: + !Not [!Equals [!Select [0, !Ref VpcSecurityGroupIds], ""]] +Resources: + ElastiCacheCluster: + Type: AWS::ElastiCache::CacheCluster + Properties: + AutoMinorVersionUpgrade: !Ref AutoMinorVersionUpgrade + AZMode: + !If [HasAZMode, !Ref AZMode, !Ref "AWS::NoValue"] + CacheNodeType: !Ref CacheNodeType + CacheParameterGroupName: !Ref CacheParameterGroupName + CacheSubnetGroupName: !Ref CacheSubnetGroupName + ClusterName: !Ref ClusterName + Engine: !Ref Engine + EngineVersion: !Ref EngineVersion + NumCacheNodes: !Ref NumCacheNodes + Port: !Ref Port + PreferredAvailabilityZone: + !If [HasPreferredAvailabilityZone, !Ref PreferredAvailabilityZone, !Ref "AWS::NoValue"] + PreferredAvailabilityZones: + !If [HasPreferredAvailabilityZones, !Ref PreferredAvailabilityZones, !Ref "AWS::NoValue"] + PreferredMaintenanceWindow: !Ref PreferredMaintenanceWindow + SnapshotWindow: !Ref SnapshotWindow + Tags: + - Key: Namespace + Value: !Ref Namespace + - Key: ResourceVersion + Value: !Ref ResourceVersion + - Key: ResourceName + Value: !Ref ResourceName + - Key: ClusterName + Value: !Ref ClusterName + - Key: Heritage + Value: operator.aws + VpcSecurityGroupIds: + !If [HasVpcSecurityGroupIds, !Ref VpcSecurityGroupIds, !Ref "AWS::NoValue"] +Outputs: + RedisEndpointAddress: + Value: !GetAtt + - ElastiCacheCluster + - RedisEndpoint.Address + Condition: IsRedis + Description: The DNS address of the configuration endpoint for the Redis cache cluster. + RedisEndpointPort: + Value: !GetAtt + - ElastiCacheCluster + - RedisEndpoint.Port + Condition: IsRedis + Description: The port number of the configuration endpoint for the Redis cache cluster. + ConfigurationEndpointAddress: + Value: !GetAtt + - ElastiCacheCluster + - ConfigurationEndpoint.Address + Condition: IsMemcached + Description: The DNS address of the configuration endpoint for the Memcached cache cluster. + ConfigurationEndpointPort: + Value: !GetAtt + - ElastiCacheCluster + - ConfigurationEndpoint.Port + Condition: IsMemcached + Description: The port number of the configuration endpoint for the Memcached cache cluster. \ No newline at end of file diff --git a/cmd/aws-service-operator/main.go b/cmd/aws-service-operator/main.go index c7f4504fd..b3322432d 100644 --- a/cmd/aws-service-operator/main.go +++ b/cmd/aws-service-operator/main.go @@ -50,7 +50,7 @@ func init() { rootCmd.PersistentFlags().StringVarP(&awsRegion, "region", "r", "us-west-2", "AWS Region for resources to be created in") rootCmd.PersistentFlags().StringVarP(&logLevel, "loglevel", "l", "Info", "Log level for the CLI") rootCmd.PersistentFlags().StringVarP(&logFile, "logfile", "", "", "Log file for the CLI") - rootCmd.PersistentFlags().StringVarP(&resources, "resources", "", "cloudformationtemplate,dynamodb,ecrrepository,s3bucket,snssubscription,snstopic,sqsqueue", "Comma delimited list of CRDs to deploy") + rootCmd.PersistentFlags().StringVarP(&resources, "resources", "", "cloudformationtemplate,dynamodb,ecrrepository,elasticache,s3bucket,snssubscription,snstopic,sqsqueue", "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.") diff --git a/code-generation/Makefile b/code-generation/Makefile index ec204c842..d3584e581 100644 --- a/code-generation/Makefile +++ b/code-generation/Makefile @@ -16,6 +16,7 @@ install-bindata: .PHONY: update-bindata update-bindata: go generate ./pkg/codegen/ + go fmt ./... .PHONY: rebuild rebuild: update-bindata build diff --git a/code-generation/pkg/codegen/assets/operator.go.templ b/code-generation/pkg/codegen/assets/operator.go.templ index 5ff114016..e2ade5f06 100644 --- a/code-generation/pkg/codegen/assets/operator.go.templ +++ b/code-generation/pkg/codegen/assets/operator.go.templ @@ -294,7 +294,7 @@ func syncAdditionalResources(config config.Config, s *awsV1alpha1.{{.Spec.Kind}} {{ if .Spec.AdditionalResources.Services }}services := []string{}{{end}} {{- range $resource := .Spec.AdditionalResources.Services }} {{- if eq $resource.Type "ExternalName"}} - {{$resource.Name}} := helpers.CreateExternalNameService(config, s, s.Name, s.Namespace, "{{$resource.ExternalName}}", {{(index $resource.Ports 0).Port}}) + {{$resource.Name}} := helpers.CreateExternalNameService(config, s, s.Name, s.Namespace, "{{$resource.ExternalName}}", "{{(index $resource.Ports 0).Port}}") services = append(services, {{$resource.Name}}) {{- end}} {{- end}} diff --git a/code-generation/pkg/codegen/codegen.go b/code-generation/pkg/codegen/codegen.go index 0f4907491..3587c7270 100644 --- a/code-generation/pkg/codegen/codegen.go +++ b/code-generation/pkg/codegen/codegen.go @@ -196,7 +196,7 @@ func createFile(rootPath string, fileName string, templateName string, path stri if templateName[len(templateName)-3:] == ".go" { formatted, err = format.Source(bf.Bytes()) if err != nil { - log.Fatalf("Error formatting resolved template: %+v", err) + log.Fatalf("Error formatting resolved template %s: %+v", templateName, err) } } diff --git a/configs/aws-service-operator-role.yaml b/configs/aws-service-operator-role.yaml index 5c817b571..c7a527bec 100644 --- a/configs/aws-service-operator-role.yaml +++ b/configs/aws-service-operator-role.yaml @@ -47,7 +47,8 @@ Resources: "cloudformation:*", "ecr:*", "dynamodb:*", - "s3:*" + "s3:*", + "elasticache:*" ], "Resource": "*" } diff --git a/examples/cloudformationtemplates/elasticache.yaml b/examples/cloudformationtemplates/elasticache.yaml new file mode 100644 index 000000000..815bcb6ce --- /dev/null +++ b/examples/cloudformationtemplates/elasticache.yaml @@ -0,0 +1,168 @@ +apiVersion: service-operator.aws/v1alpha1 +kind: CloudFormationTemplate +metadata: + name: elasticache +data: + key: elasticache.yaml + template: | + AWSTemplateFormatVersion: "2010-09-09" + Description: 'AWS Operator - Amazon Elasticache Cluster' + Parameters: + Namespace: + Description: >- + This is the namespace for the Kubernetes object. + Type: String + ResourceVersion: + Type: String + Description: >- + This is the resource version for the Kubernetes object. + ResourceName: + Description: >- + This is the resource name for the Kubernetes object + Type: String + AutoMinorVersionUpgrade: + Description: >- + Indicates that minor engine upgrades will be applied automatically to the cache cluster during the maintenance window. + Type: String + Default: false + AZMode: + Description: >- + For Memcached cache clusters, indicates whether the nodes are created in a single Availability Zone or across multiple Availability Zones in the cluster's region. + Type: String + CacheNodeType: + Description: >- + The compute and memory capacity of nodes in a cache cluster. + https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/CacheNodes.SupportedTypes.html + Type: String + Default: cache.m5.large + CacheParameterGroupName: + Description: >- + The name of the cache parameter group that is associated with this cache cluster. + Type: String + CacheSubnetGroupName: + Description: >- + The cache subnet group that you associate with a cache cluster. + "Required: Conditional. If you specified the VpcSecurityGroupIds property, you must specify this property." + Type: String + ClusterName: + Description: >- + This is the cluster name for the operator + Type: String + Engine: + Description: >- + The name of the cache engine to be used for this cache cluster, such as memcached or redis. + Type: String + Default: "redis" + EngineVersion: + Description: >- + The version of the cache engine to be used for this cluster. + Type: String + Default: "5.0.0" + NotificationTopicArn: + Description: >- + The Amazon Resource Name (ARN) of the Amazon Simple Notification Service (SNS) topic to which notifications will be sent. + Type: String + NumCacheNodes: + Description: >- + The number of cache nodes that the cache cluster should have. + Type: Number + Default: "1" + Port: + Description: >- + The port number on which each of the cache nodes will accept connections. + Type: Number + PreferredMaintenanceWindow: + Description: >- + The weekly time range (in UTC) during which system maintenance can occur. + Type: String + Default: mon:05:00-mon:09:00 + PreferredAvailabilityZone: + Description: >- + The Amazon EC2 Availability Zone in which the cache cluster is created. + Type: String + PreferredAvailabilityZones: + Description: >- + For Memcached cache clusters, the list of Availability Zones in which cache nodes are created. The number of Availability Zones listed must equal the number of cache nodes. For example, if you want to create three nodes in two different Availability Zones, you can specify ["us-east-1a", "us-east-1a", "us-east-1b"], which would create two nodes in us-east-1a and one node in us-east-1b. + Type: CommaDelimitedList + SnapshotWindow: + Description: >- + For Redis cache clusters, the daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your node group. For example, you can specify 05:00-09:00. + Type: String + Default: "05:00-09:00" + VpcSecurityGroupIds: + Description: >- + A list of VPC security group IDs. If your cache cluster isn't in a VPC, specify the CacheSecurityGroupNames property instead. + Type: CommaDelimitedList + Conditions: + IsRedis: + !Equals [!Ref Engine, "redis"] + IsMemcached: + !Equals [!Ref Engine, "memcached"] + HasAZMode: + !Not [!Equals [!Ref AZMode, ""]] + HasPreferredAvailabilityZones: + !Not [!Equals [!Select [0, !Ref PreferredAvailabilityZones], ""]] + HasPreferredAvailabilityZone: + !Not [!Equals [!Ref PreferredAvailabilityZone, ""]] + HasVpcSecurityGroupIds: + !Not [!Equals [!Select [0, !Ref VpcSecurityGroupIds], ""]] + Resources: + ElastiCacheCluster: + Type: AWS::ElastiCache::CacheCluster + Properties: + AutoMinorVersionUpgrade: !Ref AutoMinorVersionUpgrade + AZMode: + !If [HasAZMode, !Ref AZMode, !Ref "AWS::NoValue"] + CacheNodeType: !Ref CacheNodeType + CacheParameterGroupName: !Ref CacheParameterGroupName + CacheSubnetGroupName: !Ref CacheSubnetGroupName + ClusterName: !Ref ClusterName + Engine: !Ref Engine + EngineVersion: !Ref EngineVersion + NumCacheNodes: !Ref NumCacheNodes + Port: !Ref Port + PreferredAvailabilityZone: + !If [HasPreferredAvailabilityZone, !Ref PreferredAvailabilityZone, !Ref "AWS::NoValue"] + PreferredAvailabilityZones: + !If [HasPreferredAvailabilityZones, !Ref PreferredAvailabilityZones, !Ref "AWS::NoValue"] + PreferredMaintenanceWindow: !Ref PreferredMaintenanceWindow + SnapshotWindow: !Ref SnapshotWindow + Tags: + - Key: Namespace + Value: !Ref Namespace + - Key: ResourceVersion + Value: !Ref ResourceVersion + - Key: ResourceName + Value: !Ref ResourceName + - Key: ClusterName + Value: !Ref ClusterName + - Key: Heritage + Value: operator.aws + VpcSecurityGroupIds: + !If [HasVpcSecurityGroupIds, !Ref VpcSecurityGroupIds, !Ref "AWS::NoValue"] + Outputs: + RedisEndpointAddress: + Value: !GetAtt + - ElastiCacheCluster + - RedisEndpoint.Address + Condition: IsRedis + Description: The DNS address of the configuration endpoint for the Redis cache cluster. + RedisEndpointPort: + Value: !GetAtt + - ElastiCacheCluster + - RedisEndpoint.Port + Condition: IsRedis + Description: The port number of the configuration endpoint for the Redis cache cluster. + ConfigurationEndpointAddress: + Value: !GetAtt + - ElastiCacheCluster + - ConfigurationEndpoint.Address + Condition: IsMemcached + Description: The DNS address of the configuration endpoint for the Memcached cache cluster. + ConfigurationEndpointPort: + Value: !GetAtt + - ElastiCacheCluster + - ConfigurationEndpoint.Port + Condition: IsMemcached + Description: The port number of the configuration endpoint for the Memcached cache cluster. + diff --git a/examples/elasticache_memcached.yaml b/examples/elasticache_memcached.yaml new file mode 100644 index 000000000..fd97a3eb1 --- /dev/null +++ b/examples/elasticache_memcached.yaml @@ -0,0 +1,13 @@ +apiVersion: service-operator.aws/v1alpha1 +kind: ElastiCache +metadata: + name: memcached13 +spec: + CacheSubnetGroupName: "loadtest-cluster-k8s" + VpcSecurityGroupIds: "sg-0581b94aa3c0db58c, sg-02b6d0034e8c2fa1b" + AutoMinorVersionUpgrade: true + Engine: memcached + EngineVersion: 1.5.10 + NumCacheNodes: 1 + Port: 11211 + CacheNodeType: "cache.m4.large" diff --git a/examples/elasticache_redis.yaml b/examples/elasticache_redis.yaml new file mode 100644 index 000000000..cc0c18110 --- /dev/null +++ b/examples/elasticache_redis.yaml @@ -0,0 +1,13 @@ +apiVersion: service-operator.aws/v1alpha1 +kind: ElastiCache +metadata: + name: elasticache13 +spec: + CacheSubnetGroupName: "loadtest-cluster-k8s" + VpcSecurityGroupIds: "sg-0581b94aa3c0db58c, sg-02b6d0034e8c2fa1b" + AutoMinorVersionUpgrade: true + Engine: redis + EngineVersion: 5.0.0 + NumCacheNodes: 1 + Port: 6379 + CacheNodeType: "cache.m4.large" diff --git a/models/elasticache.yaml b/models/elasticache.yaml new file mode 100644 index 000000000..dcfa9b7ba --- /dev/null +++ b/models/elasticache.yaml @@ -0,0 +1,150 @@ +apiVersion: service-operator.aws/v1alpha1 +kind: ModelDefinition +metadata: + name: ElastiCacheResource +spec: + kind: ElastiCache + type: Spec + queue: true + useCloudFormation: true + resource: + name: elasticache + plural: elasticaches + shortNames: + - name: ec + scope: Namespaced + body: + schema: + type: object + properties: + - key: elastiCacheClusterName + type: resourceName + description: | + ElastiCacheClusterName is the name of the Elasticache cluster to be created. + structKey: ElastiCacheClusterName + templateKey: ClusterName + - key: AutoMinorVersionUpgrade + type: bool + description: | + Indicates that minor engine upgrades will be applied automatically to the cache cluster during the maintenance window. + structKey: AutoMinorVersionUpgrade + templateKey: AutoMinorVersionUpgrade + - key: AZMode + type: string + description: | + For Memcached cache clusters, indicates whether the nodes are created in a single Availability Zone or across multiple Availability Zones in the cluster's region. + structKey: AZMode + templateKey: AZMode + - key: CacheNodeType + type: string + description: | + The compute and memory capacity of nodes in a cache cluster. + structKey: CacheNodeType + templateKey: CacheNodeType + - key: CacheParameterGroupName + type: string + description: | + The name of the cache parameter group that is associated with this cache cluster. + structKey: CacheParameterGroupName + templateKey: CacheParameterGroupName + - key: CacheSubnetGroupName + type: string + description: | + The cache subnet group that you associate with a cache cluster. + structKey: CacheSubnetGroupName + templateKey: CacheSubnetGroupName + - key: Engine + type: string + description: | + The name of the cache engine to be used for this cache cluster, such as memcached or redis. + structKey: Engine + templateKey: Engine + - key: EngineVersion + type: string + description: | + The version of the cache engine to be used for this cluster. + structKey: EngineVersion + templateKey: EngineVersion + - key: NotificationTopicArn + type: string + description: | + The Amazon Resource Name (ARN) of the Amazon Simple Notification Service (SNS) topic to which notifications will be sent. + structKey: NotificationTopicArn + templateKey: NotificationTopicArn + - key: NumCacheNodes + type: int + description: | + The number of cache nodes that the cache cluster should have. + structKey: NumCacheNodes + templateKey: NumCacheNodes + - key: Port + type: int + description: | + The port number on which each of the cache nodes will accept connections. + structKey: Port + templateKey: Port + - key: PreferredMaintenanceWindow + type: string + description: | + The weekly time range (in UTC) during which system maintenance can occur. + structKey: PreferredMaintenanceWindow + templateKey: PreferredMaintenanceWindow + - key: PreferredAvailabilityZone + type: string + description: | + The Amazon EC2 Availability Zone in which the cache cluster is created. + structKey: PreferredAvailabilityZone + templateKey: PreferredAvailabilityZone + - key: PreferredAvailabilityZones + type: string + description: + For Memcached cache clusters, the comma seperated list of Availability Zones in which cache nodes are created. The number of Availability Zones listed must equal the number of cache nodes. For example, if you want to create three nodes in two different Availability Zones, you can specify ["us-east-1a", "us-east-1a", "us-east-1b"], which would create two nodes in us-east-1a and one node in us-east-1b. + structKey: PreferredAvailabilityZones + templateKey: PreferredAvailabilityZones + - key: SnapshotWindow + type: string + description: | + For Redis cache clusters, the daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your node group. For example, you can specify 05:00-09:00. + structKey: SnapshotWindow + templateKey: SnapshotWindow + - key: VpcSecurityGroupIds + type: string + description: | + A comma seperated list of VPC security group IDs. If your cache cluster isn't in a VPC, specify the CacheSecurityGroupNames property instead. + structKey: VpcSecurityGroupIds + templateKey: VpcSecurityGroupIds + output: + schema: + type: object + properties: + - key: RedisEndpointAddress + type: string + description: | + The DNS address of the configuration endpoint for the Redis cache cluster. + structKey: RedisEndpointAddress + templateKey: RedisEndpointAddress + - key: RedisEndpointPort + type: string + description: | + The port number of the configuration endpoint for the Redis cache cluster. + structKey: RedisEndpointPort + templateKey: RedisEndpointPort + - key: ConfigurationEndpoint + type: string + description: | + The DNS address of the configuration endpoint for the Memcached cache cluster. + structKey: ConfigurationEndpointAddress + templateKey: ConfigurationEndpointAddress + - key: ConfigurationEndpointPort + type: string + description: | + The port number of the configuration endpoint for the Memcached cache cluster. + structKey: ConfigurationEndpointPort + templateKey: ConfigurationEndpointPort + additionalResources: + services: + - name: ElastiCacheAddressSvc + type: ExternalName + externalName: "{{ if .Obj.Output.RedisEndpointAddress }}{{ .Obj.Output.RedisEndpointAddress }}{{ else }}{{ .Obj.Output.ConfigurationEndpointAddress }}{{end}}" + ports: + - port: "{{ if .Obj.Output.RedisEndpointPort }}{{ .Obj.Output.RedisEndpointPort }}{{ else }}{{ .Obj.Output.ConfigurationEndpointPort }}{{end}}" diff --git a/pkg/helpers/service.go b/pkg/helpers/service.go index 3e52e05cf..7be3d4fad 100644 --- a/pkg/helpers/service.go +++ b/pkg/helpers/service.go @@ -1,13 +1,16 @@ package helpers import ( + "strconv" + "strings" + "github.com/awslabs/aws-service-operator/pkg/config" apiv1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // CreateExternalNameService will create a Kubernetes Servic Using ExternalName types -func CreateExternalNameService(config config.Config, resource interface{}, svcName string, svcNamespace string, externalNameTemplate string, svcPort int32) string { +func CreateExternalNameService(config config.Config, resource interface{}, svcName string, svcNamespace string, externalNameTemplate string, svcPortTemplate string) string { logger := config.Logger externalName, err := Templatize(externalNameTemplate, Data{Obj: resource, Config: config}) @@ -16,6 +19,23 @@ func CreateExternalNameService(config config.Config, resource interface{}, svcNa return "" } + svcPortString, err := Templatize(svcPortTemplate, Data{Obj: resource, Config: config}) + if err != nil { + logger.WithError(err).Error("error parsing service port template") + return "" + } + + svcPortStripSlash := strings.Replace(svcPortString, "\\", "", -1) + + svcPortInt64, err := strconv.ParseInt(svcPortStripSlash, 0, 16) + if err != nil { + logger.WithError(err).Error("error converting service port template string to int") + return "" + } + + // ParseInt only returns an int64, must convert to int32 for apiv1.ServicePort field + svcPort := int32(svcPortInt64) + service := &apiv1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: KubernetesResourceName(svcName), diff --git a/readme.adoc b/readme.adoc index 524f32c5c..9bdeadd83 100644 --- a/readme.adoc +++ b/readme.adoc @@ -90,3 +90,7 @@ If you would like to tear everything down - run the following commands. kubectl delete ecr example-repository-name kubectl get crd | grep ".operator.aws" | awk '{print $1}' | xargs kubectl delete crd kubectl delete -f configs/aws-service-operator.yaml + +== Developer Docs + +[Here](development.adoc)