Skip to content

Commit 10e6854

Browse files
committed
chore(charts): use condition
1 parent 63efe5a commit 10e6854

9 files changed

Lines changed: 64 additions & 69 deletions

File tree

charts/controller/templates/_helpers.tpl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ env:
1111
- name: "K8S_API_VERIFY_TLS"
1212
value: "{{ .Values.k8sApiVerifyTls }}"
1313
- name: "DRYCC_REGISTRY_LOCATION"
14-
value: "{{ .Values.global.registryLocation }}"
14+
value: {{ ternary "on-cluster" "off-cluster" .Values.registry.enabled }}
1515
- name: "DRYCC_REGISTRY_SECRET_PREFIX"
16-
value: "{{ .Values.global.registrySecretPrefix }}"
16+
value: "{{ .Values.registrySecretPrefix }}"
1717
- name: "IMAGE_PULL_POLICY"
1818
value: "{{ .Values.appImagePullPolicy }}"
1919
- name: "DRYCC_FILER_IMAGE"
@@ -63,7 +63,7 @@ env:
6363
secretKeyRef:
6464
name: controller-creds
6565
key: valkey-url
66-
{{- else if eq .Values.global.valkeyLocation "on-cluster" }}
66+
{{- else if .Values.valkey.enabled }}
6767
- name: VALKEY_PASSWORD
6868
valueFrom:
6969
secretKeyRef:
@@ -85,7 +85,7 @@ env:
8585
secretKeyRef:
8686
name: controller-creds
8787
key: database-url
88-
{{- else if eq .Values.global.databaseLocation "on-cluster" }}
88+
{{- else if .Values.database.enabled }}
8989
- name: DRYCC_PG_USER
9090
valueFrom:
9191
secretKeyRef:
@@ -119,7 +119,7 @@ env:
119119
secretKeyRef:
120120
name: controller-creds
121121
key: prometheus-url
122-
{{- else if eq .Values.global.prometheusLocation "on-cluster" }}
122+
{{- else if .Values.prometheus.enabled }}
123123
- name: "DRYCC_PROMETHEUS_USERNAME"
124124
valueFrom:
125125
secretKeyRef:
@@ -133,7 +133,7 @@ env:
133133
- name: "DRYCC_PROMETHEUS_URL"
134134
value: "http://$(DRYCC_PROMETHEUS_USERNAME):$(DRYCC_PROMETHEUS_PASSWORD)@drycc-prometheus.{{$.Release.Namespace}}.svc.{{$.Values.global.clusterDomain}}:9090"
135135
{{- end }}
136-
{{- if eq .Values.global.passportLocation "on-cluster"}}
136+
{{- if .Values.passport.enabled }}
137137
- name: "DRYCC_PASSPORT_URL"
138138
{{- if .Values.global.certManagerEnabled }}
139139
value: https://drycc-passport.{{ .Values.global.platformDomain }}

charts/controller/templates/controller-clusterrole.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,9 @@ rules:
5454
- apiGroups: ["extensions", "autoscaling"]
5555
resources: ["horizontalpodautoscalers"]
5656
verbs: ["get", "list", "create", "update", "delete"]
57-
- apiGroups: ["extensions"]
58-
resources: ["ingresses"]
59-
verbs: ["get", "list", "watch", "create", "update", "delete"]
6057
- apiGroups: ["cert-manager.io"]
6158
resources: ["certificates", "certificaterequest", "issuers"]
6259
verbs: ["get", "list", "watch", "create", "update", "delete"]
63-
- apiGroups: ["networking.k8s.io"]
64-
resources: ["ingresses"]
65-
verbs: ["get", "list", "create", "delete", "deletecollection", "patch", "update"]
66-
- apiGroups: ["networking.k8s.io"]
67-
resources: ["ingressclasses"]
68-
verbs: ["get"]
6960
- apiGroups: ["apps"]
7061
resources: ["replicasets"]
7162
verbs: ["get", "list", "watch", "delete"]

charts/controller/templates/controller-secret-creds.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@ data:
2626
{{- if (.Values.passportSecret) }}
2727
passport-secret: {{ .Values.passportSecret | b64enc }}
2828
{{- end }}
29+
{{- if (.Values.registryHost) }}
30+
registry-host: {{ .Values.registryHost | b64enc }}
31+
registry-username: {{ .Values.registryUsername | b64enc }}
32+
registry-password: {{ .Values.registryPassword | b64enc }}
33+
{{- end }}
2934
django-secret-key: {{ (include "common.secrets.lookup" (dict "secret" "controller-creds" "key" "django-secret-key" "defaultValue" (randAscii 64) "context" $)) }}
3035
deploy-hook-secret-key: {{ (include "common.secrets.lookup" (dict "secret" "controller-creds" "key" "deploy-hook-secret-key" "defaultValue" (randAscii 64) "context" $)) }}

charts/controller/values.yaml

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ appImagePullPolicy: "Always"
3535
filerImage: "registry.drycc.cc/drycc/filer:canary"
3636
filerImagePullPolicy: "Always"
3737
# Set storageClassName. It is used for application.
38-
appStorageClass: "{{ .Values.storage.csi.storageClassName }}"
38+
appStorageClass: "longhorn"
3939
# Set runtimeClassName. It is used for application.
4040
appRuntimeClass: ""
4141
# Set appDNSPolicy. It is used for application.
@@ -63,10 +63,14 @@ databaseReplicaUrl: ""
6363
passportUrl: ""
6464
passportKey: ""
6565
passportSecret: ""
66+
# prometheusUrl is will no longer use the built-in prometheus component
67+
prometheusUrl: ""
6668
# Workflow-manager Configuration Options
6769
workflowManagerUrl: ""
6870
workflowManagerAccessKey: ""
6971
workflowManagerSecretKey: ""
72+
# Prefix for the imagepull secret created when using private registry
73+
registrySecretPrefix: "private-registry"
7074

7175
# limit specs, plans config
7276
config:
@@ -133,41 +137,26 @@ mutate:
133137
extraMatchLabels:
134138
component: "drycc-controller-mutate"
135139

136-
storage:
137-
csi:
138-
storageClassName: drycc-storage
140+
valkey:
141+
enabled: true
142+
143+
database:
144+
enabled: true
145+
146+
registry:
147+
enabled: true
148+
149+
passport:
150+
enabled: true
151+
152+
prometheus:
153+
enabled: true
139154

140155
global:
141156
# Admin email, used for each component to send email to administrator
142157
email: "drycc@drycc.cc"
143-
# Set the storage backend
144-
#
145-
# Valid values are:
146-
# - s3: Store persistent data in AWS S3 (configure in S3 section)
147-
# - azure: Store persistent data in Azure's object storage
148-
# - gcs: Store persistent data in Google Cloud Storage
149-
# - minio: Store persistent data on in-cluster Minio server
150-
storage: minio
151-
# Set the location of Workflow's PostgreSQL database
152-
#
153-
# Valid values are:
154-
# - on-cluster: Run PostgreSQL within the Kubernetes cluster (credentials are generated
155-
# automatically; backups are sent to object storage
156-
# configured above)
157-
# - off-cluster: Run PostgreSQL outside the Kubernetes cluster (configure in database section)
158-
databaseLocation: "on-cluster"
159-
# Set the location of Workflow's Registry
160-
#
161-
# Valid values are:
162-
# - on-cluster: Run registry within the Kubernetes cluster
163-
# - off-cluster: Use registry outside the Kubernetes cluster (example: drycc registry,self-hosted)
164-
registryLocation: "on-cluster"
165-
# Prefix for the imagepull secret created when using private registry
166-
registrySecretPrefix: "private-registry"
167158
# GatewayClass is cluster-scoped resource defined by the infrastructure provider.
168159
gatewayClass: ""
169-
# Please check `kubernetes.io/ingress.class`
170-
ingressClass: ""
171160
# A domain name consists of one or more parts.
172161
# Periods (.) are used to separate these parts.
173162
# Each part must be 1 to 63 characters in length and can contain lowercase letters, digits, and hyphens (-).
@@ -179,10 +168,3 @@ global:
179168
platformDomain: ""
180169
# Whether cert_manager is enabled to automatically generate controller certificates
181170
certManagerEnabled: true
182-
passportLocation: "on-cluster"
183-
# Set the location of Workflow's prometheus cluster
184-
#
185-
# Valid values are:
186-
# - on-cluster: Run prometheus within the Kubernetes cluster
187-
# - off-cluster: prometheus is running outside of the cluster and credentials and connection information will be provided.
188-
prometheusLocation: "on-cluster"

rootfs/api/models/app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,12 +1149,12 @@ def _get_private_registry_config(self, ptype, image, registry=None):
11491149
password = registry.get('password')
11501150
elif settings.REGISTRY_LOCATION == 'off-cluster':
11511151
secret = self.scheduler().secret.get(
1152-
settings.WORKFLOW_NAMESPACE, 'registry-secret').json()
1153-
username = secret['data']['username']
1154-
password = secret['data']['password']
1155-
hostname = secret['data']['hostname']
1152+
settings.WORKFLOW_NAMESPACE, 'controller-creds').json()
1153+
hostname = secret['data']['registry-host']
11561154
if hostname == '':
11571155
hostname = docker_auth.INDEX_URL
1156+
username = secret['data']['registry-username']
1157+
password = secret['data']['registry-password']
11581158
name = name + '-' + settings.REGISTRY_LOCATION
11591159
else:
11601160
return None, None, None

rootfs/api/tests/test_build.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,13 @@ def test_new_build_does_not_scale_up_automatically(self, mock_requests):
510510
self.assertEqual(response.status_code, 200, response.data)
511511
self.assertEqual(len(response.data['results']), 0)
512512

513-
def test_build_image_in_registry(self, mock_requests):
513+
def test_build_image_in_registry_ok(self, mock_requests):
514514
"""When the image is already in the drycc registry no pull/tag/push happens"""
515515
app_id = self.create_app()
516516

517517
# post an image as a build using registry hostname
518518
url = f"/v2/apps/{app_id}/build"
519-
image = '127.0.0.1:5000/autotest/example'
519+
image = 'registry.drycc.cc:5000/autotest/example'
520520
body = {'image': image, 'stack': 'container'}
521521
response = self.client.post(url, body)
522522
self.assertEqual(response.status_code, 201, response.data)
@@ -527,7 +527,7 @@ def test_build_image_in_registry(self, mock_requests):
527527

528528
# post an image as a build using registry hostname + port
529529
url = f"/v2/apps/{app_id}/build"
530-
image = '127.0.0.1:5000/autotest/example'
530+
image = 'registry.drycc.cc:5000/autotest/example'
531531
body = {'image': image, 'stack': 'container'}
532532
response = self.client.post(url, body)
533533
self.assertEqual(response.status_code, 201, response.data)
@@ -536,6 +536,18 @@ def test_build_image_in_registry(self, mock_requests):
536536
release = build.app.release_set.latest()
537537
self.assertEqual(release.get_deploy_image(PTYPE_WEB), image)
538538

539+
def test_build_image_in_registry_err(self, mock_requests):
540+
"""When the image is already in the drycc registry no pull/tag/push happens"""
541+
app_id = self.create_app()
542+
543+
# post an image as a build using registry hostname
544+
url = f"/v2/apps/{app_id}/build"
545+
for host in ['127.0.0.1', 'localhost', 'localhost:5000', '127.0.0.1:5000']:
546+
image = f'{host}/autotest/example'
547+
body = {'image': image, 'stack': 'container'}
548+
response = self.client.post(url, body)
549+
self.assertEqual(response.status_code, 400, response.data)
550+
539551
def test_build_image_in_registry_with_auth(self, mock_requests):
540552
"""add authentication to the build"""
541553
app_id = self.create_app()

rootfs/api/tests/test_release.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def test_get_image(self, mock_requests):
138138
app_id = self.create_app()
139139
url = f"/v2/apps/{app_id}/build"
140140
body = {
141-
'image': '127.0.0.1:5555/autotest/example:git-fadf1231',
141+
'image': 'registry.drycc.cc:5555/autotest/example:git-fadf1231',
142142
'stack': 'heroku-18',
143143
'sha': 'a'*40,
144144
'dryccfile': {
@@ -206,15 +206,15 @@ def test_get_image(self, mock_requests):
206206
"deploy": {
207207
"command": ["bash", "-c"],
208208
"args": ["bundle exec puma -C config/puma.rb"],
209-
"image": "127.0.0.1:7070/myapp/web:git-123fsa1",
209+
"image": "registry.drycc.cc:7070/myapp/web:git-123fsa1",
210210
},
211211
},
212212
},
213213
},
214214
}
215-
default_image = '127.0.0.1:5555/autotest/example:git-fadf1231'
216-
worker_image = "127.0.0.1:5555/autotest/example:git-fadf1231-worker"
217-
worker_4_image = "127.0.0.1:7070/myapp/web:git-123fsa1"
215+
default_image = 'registry.drycc.cc:5555/autotest/example:git-fadf1231'
216+
worker_image = "registry.drycc.cc:5555/autotest/example:git-fadf1231-worker"
217+
worker_4_image = "registry.drycc.cc:7070/myapp/web:git-123fsa1"
218218

219219
with mock.patch('scheduler.resources.pod.Pod.watch') as mock_kube:
220220
mock_kube.return_value = ['up', 'down']

rootfs/api/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
User = get_user_model()
4646
logger = logging.getLogger(__name__)
47+
is_loopback = re.compile(r'^(localhost|127\.0\.0\.1)(:\d+)?/').match
4748
oauth_cache_manager = OauthCacheManager()
4849
NAMESPACE = getattr(settings, setting_name('URL_NAMESPACE'), None) or 'social'
4950

@@ -352,6 +353,10 @@ class BuildViewSet(ReleasableViewSet):
352353
serializer_class = serializers.BuildSerializer
353354

354355
def post_save(self, build):
356+
for ptype in build.ptypes:
357+
image = build.get_image(ptype)
358+
if is_loopback(image):
359+
raise DryccException("image must not use the loopback address")
355360
build.create_release(self.request.user)
356361
super(BuildViewSet, self).post_save(build)
357362

rootfs/scheduler/mock.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,14 +1093,14 @@ def __init__(self, url, k8s_api_verify_tls=True):
10931093
self.secret.create('drycc', 'objectstorage-keyfile', secrets)
10941094

10951095
try:
1096-
self.secret.get('drycc', 'registry-secret')
1096+
self.secret.get('drycc', 'controller-creds')
10971097
except KubeHTTPException:
10981098
secrets = {
1099-
'username': 'test',
1100-
'password': 'test',
1101-
'hostname': ''
1099+
'registry-host': '',
1100+
'registry-username': 'test',
1101+
'registry-password': 'test',
11021102
}
1103-
self.secret.create('drycc', 'registry-secret', secrets)
1103+
self.secret.create('drycc', 'controller-creds', secrets)
11041104

11051105
try:
11061106
self.ns.get('duplicate')

0 commit comments

Comments
 (0)