Skip to content

Commit

Permalink
Merge pull request #1009 from porter-dev/jose-fully-ported/elasticach…
Browse files Browse the repository at this point in the history
…e-redis-chart

Setup elasticache-redis chart
  • Loading branch information
jose-fully-ported authored Nov 23, 2023
2 parents 7c2956c + 5dbddbd commit f19a186
Show file tree
Hide file tree
Showing 8 changed files with 313 additions and 0 deletions.
18 changes: 18 additions & 0 deletions addons/elasticache-redis/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
annotations:
category: cache
apiVersion: v2
appVersion: "7.0"
description: A fast nosql datastore used for caching, real-time interactions, and more.
home: https://github.com/porter-dev/porter-charts/tree/master/addons/elasticache-redis
icon: https://raw.githubusercontent.com/aws/eks-charts/master/docs/logo/aws.png
keywords:
- redis
- cache
- nosql
- elasticache
- DATA_STORE
maintainers:
- name: Porter Technologies, Inc.
email: [email protected]
name: elasticache-redis
version: 0.0.0
31 changes: 31 additions & 0 deletions addons/elasticache-redis/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{- define "generate_static_password" -}}
{{- /* Create "tmp_vars" dict inside ".Release" to store various stuff. */ -}}
{{- if not (index .Release "tmp_vars") -}}
{{- $_ := set .Release "tmp_vars" dict -}}
{{- end -}}
{{- /* Some random ID of this password, in case there will be other random values alongside this instance. */ -}}
{{- $key := printf "%s_%s" .Release.Name "REDIS_PASS" -}}
{{- /* If a password isn't set and the $key does not yet exist in .Release.tmp_vars, then... */ -}}
{{- if .Values.config.masterUserPassword -}}
{{- /* ... set the specified password as $key */ -}}
{{- $_ := set .Release.tmp_vars $key (.Values.config.masterUserPassword) -}}
{{- else -}}
{{- if not (index .Release.tmp_vars $key) -}}
{{- /* ... store random password under the $key */ -}}
{{- $_ := set .Release.tmp_vars $key (randAlphaNum 20) -}}
{{- end -}}
{{- end -}}
{{- /* Retrieve previously generated value. */ -}}
{{- index .Release.tmp_vars $key -}}
{{- end -}}
{{- define "random_pw_reusable" -}}
{{- if .Release.IsUpgrade -}}
{{- $data := default dict (lookup "v1" "Secret" "porter-env-group" (printf "%s.1" .Values.config.name)).data -}}
{{- if $data -}}
{{- index $data "REDIS_PASS" | b64dec -}}
{{- end -}}
{{- else -}}
{{- (include "generate_static_password" .) -}}
{{- end -}}
{{- end -}}
21 changes: 21 additions & 0 deletions addons/elasticache-redis/templates/parameter_group.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
apiVersion: elasticache.services.k8s.aws/v1alpha1
kind: CacheParameterGroup
metadata:
name: "{{ .Values.config.name }}"
namespace: "{{ .Release.Namespace }}"
annotations:
services.k8s.aws/region: "{{ .Values.vpcConfig.awsRegion }}"
labels:
porter.run/helm-release-name: "{{ .Release.Name }}"
spec:
cacheParameterGroupName: "{{ .Values.config.name }}-redis{{ (semver (toString .Values.config.engineVersion)).Major }}"
cacheParameterGroupFamily: "redis{{ (semver (toString .Values.config.engineVersion)).Major }}"
description: "Parameter group for {{ .Values.config.name }}"
tags:
- key: "porter.run/managed"
value: "true"
- key: "porter.run/service"
value: "elasticache"
- key: "porter.run/service-name"
value: "{{ $.Values.config.name }}"
43 changes: 43 additions & 0 deletions addons/elasticache-redis/templates/replication_group.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
apiVersion: elasticache.services.k8s.aws/v1alpha1
kind: ReplicationGroup
metadata:
name: "{{ .Values.config.name }}"
namespace: "{{ .Release.Namespace }}"
annotations:
services.k8s.aws/region: "{{ .Values.vpcConfig.awsRegion }}"
labels:
porter.run/helm-release-name: "{{ .Release.Name }}"
spec:
atRestEncryptionEnabled: true
authToken:
namespace: porter-env-group
name: "{{ .Values.config.name }}.1"
key: REDIS_PASS
automaticFailoverEnabled: true
cacheNodeType: "{{ .Values.config.instanceClass }}"
cacheSubnetGroupName: "{{ .Values.config.name }}"
cacheParameterGroupRef:
from:
name: "{{ .Values.config.name }}"
description: "{{ .Values.config.name }} Redis Replication Group"
engine: redis
engineVersion: "{{ .Values.config.engineVersion }}"
# prettier-ignore
multiAZEnabled: {{ .Values.config.multiAZ }}
numNodeGroups: 1
port: 6379
replicasPerNodeGroup: 1
replicationGroupID: "{{ .Values.config.name }}"
securityGroupRefs:
- from:
name: "{{ .Values.config.name }}-elasticache"
snapshotRetentionLimit: 7
tags:
- key: "porter.run/managed"
value: "true"
- key: "porter.run/service"
value: "elasticache"
- key: "porter.run/service-name"
value: "{{ $.Values.config.name }}"
transitEncryptionEnabled: true
67 changes: 67 additions & 0 deletions addons/elasticache-redis/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: "{{ .Values.config.name }}.1"
namespace: porter-env-group
labels:
porter.run/environment-group-name: "{{ .Values.config.name }}.1"
porter.run/environment-group-version: "1"
porter.run/environment-group-datastore: "{{ .Values.config.name }}"
porter.run/environment-group-datastore-type: redis
porter.run/helm-release-name: "{{ .Release.Name }}"
data:
REDIS_PASS: "{{- include "random_pw_reusable" . | b64enc }}"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ .Values.config.name }}.1"
namespace: porter-env-group
labels:
porter.run/environment-group-name: "{{ .Values.config.name }}.1"
porter.run/environment-group-version: "1"
porter.run/environment-group-datastore: "{{ .Values.config.name }}"
porter.run/environment-group-datastore-type: redis
porter.run/helm-release-name: "{{ .Release.Name }}"
---
apiVersion: services.k8s.aws/v1alpha1
kind: FieldExport
metadata:
name: "{{ .Values.config.name }}-host"
namespace: "{{ .Release.Namespace }}"
labels:
porter.run/helm-release-name: "{{ .Release.Name }}"
spec:
to:
name: "{{ .Values.config.name }}.1"
namespace: porter-env-group
key: REDIS_HOST
kind: configmap
from:
path: ".status.clusterEndpoint.address"
resource:
group: elasticache.services.k8s.aws
kind: ReplicationGroup
name: "{{ .Values.config.name }}"
---
apiVersion: services.k8s.aws/v1alpha1
kind: FieldExport
metadata:
name: "{{ .Values.config.name }}-port"
namespace: "{{ .Release.Namespace }}"
labels:
porter.run/helm-release-name: "{{ .Release.Name }}"
spec:
to:
name: "{{ .Values.config.name }}.1"
namespace: porter-env-group
key: REDIS_PORT
kind: configmap
from:
path: ".status.clusterEndpoint.port"
resource:
group: elasticache.services.k8s.aws
kind: ReplicationGroup
name: "{{ .Values.config.name }}"
29 changes: 29 additions & 0 deletions addons/elasticache-redis/templates/security_group.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
apiVersion: ec2.services.k8s.aws/v1alpha1
kind: SecurityGroup
metadata:
name: "{{ .Values.config.name }}-elasticache"
namespace: "{{ .Release.Namespace }}"
annotations:
services.k8s.aws/region: "{{ .Values.vpcConfig.awsRegion }}"
labels:
porter.run/helm-release-name: "{{ .Release.Name }}"
spec:
description: SecurityGroup
name: "{{ .Values.config.name }}-elasticache"
vpcID: "{{ .Values.vpcConfig.vpcID }}"
ingressRules:
- ipProtocol: tcp
ipRanges:
- cidrIP: "0.0.0.0/0"
fromPort: 6379
toPort: 6379
tags:
- key: "Name"
value: "{{ .Values.config.name }}-elasticache"
- key: "porter.run/managed"
value: "true"
- key: "porter.run/service"
value: "elasticache"
- key: "porter.run/service-name"
value: "{{ $.Values.config.name }}"
93 changes: 93 additions & 0 deletions addons/elasticache-redis/templates/subnets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{{- if .Values.vpcConfig.subnetConfig }}
{{- range $k, $v := .Values.vpcConfig.subnetConfig }}
---
apiVersion: ec2.services.k8s.aws/v1alpha1
kind: RouteTable
metadata:
name: "{{ $.Values.vpcConfig.awsRegion }}-cache-{{ $.Values.config.name }}-private-{{ $v.availabilityZone }}"
namespace: "{{ $.Release.Namespace }}"
annotations:
services.k8s.aws/region: "{{ $.Values.vpcConfig.awsRegion }}"
labels:
porter.run/helm-release-name: "{{ $.Release.Name }}"
spec:
routes:
- destinationCIDRBlock: "{{ $.Values.vpcConfig.cidrBlock }}"
gatewayID: "local"
tags:
- key: "porter.run/managed"
value: "true"
- key: "porter.run/service"
value: "elasticache"
- key: "porter.run/service-name"
value: "{{ $.Values.config.name }}"
- key: "Name"
value: "{{ $.Values.vpcConfig.awsRegion }}-cache-{{ $.Values.config.name }}-private-{{ $v.availabilityZone }}"
vpcID: "{{ $.Values.vpcConfig.vpcID }}"
---
apiVersion: ec2.services.k8s.aws/v1alpha1
kind: Subnet
metadata:
name: "{{ $.Values.vpcConfig.awsRegion }}-cache-{{ $.Values.config.name }}-private-{{ $v.availabilityZone }}"
namespace: "{{ $.Release.Namespace }}"
annotations:
services.k8s.aws/region: "{{ $.Values.vpcConfig.awsRegion }}"
labels:
porter.run/helm-release-name: "{{ $.Release.Name }}"
spec:
assignIPv6AddressOnCreation: false
availabilityZone: "{{ $v.availabilityZone }}"
cidrBlock: "{{ $v.cidrBlock }}"
enableDNS64: false
enableResourceNameDNSAAAARecord: false
enableResourceNameDNSARecord: false
hostnameType: "ip-name"
mapPublicIPOnLaunch: false
routeTableRefs:
- from:
name: "{{ $.Values.vpcConfig.awsRegion }}-cache-{{ $.Values.config.name }}-private-{{ $v.availabilityZone }}"
tags:
- key: "porter.run/managed"
value: "true"
- key: "porter.run/service"
value: "elasticache"
- key: "porter.run/service-name"
value: "{{ $.Values.config.name }}"
- key: "Name"
value: "{{ $.Values.vpcConfig.awsRegion }}-cache-{{ $.Values.config.name }}-private-{{ $v.availabilityZone }}"
vpcID: "{{ $.Values.vpcConfig.vpcID }}"
{{- end }}
{{- end }}
---
apiVersion: elasticache.services.k8s.aws/v1alpha1
kind: CacheSubnetGroup
metadata:
name: "{{ .Values.config.name }}"
namespace: "{{ .Release.Namespace }}"
annotations:
services.k8s.aws/region: "{{ .Values.vpcConfig.awsRegion }}"
labels:
porter.run/helm-release-name: "{{ .Release.Name }}"
spec:
cacheSubnetGroupName: "{{ .Values.config.name }}"
cacheSubnetGroupDescription: "{{ .Values.config.name }} Subnet Group"
{{- if .Values.vpcConfig.subnetIDs }}
subnetIDs:
{{- range .Values.vpcConfig.subnetIDs }}
- {{ toYaml . }}
{{- end}}
{{- end }}
{{- if .Values.vpcConfig.subnetConfig }}
subnetRefs:
{{- range $k, $v := .Values.vpcConfig.subnetConfig }}
- from:
name: "{{ $.Values.vpcConfig.awsRegion }}-cache-{{ $.Values.config.name }}-private-{{ $v.availabilityZone }}"
{{- end }}
{{- end }}
tags:
- key: "porter.run/managed"
value: "true"
- key: "porter.run/service"
value: "elasticache"
- key: "porter.run/service-name"
value: "{{ $.Values.config.name }}"
11 changes: 11 additions & 0 deletions addons/elasticache-redis/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
config:
engineVersion: 7
instanceClass: cache.t4g.small
masterUserPassword: ""
multiAZ: true
name: ""

vpcConfig:
awsRegion: ""
subnetIDs: []
vpcID: ""

0 comments on commit f19a186

Please sign in to comment.