Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use user-provided service account #184

Merged
merged 1 commit into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/crd/bases/theketch.io_apps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2312,6 +2312,10 @@ spec:
type: object
type: object
type: array
serviceAccountName:
description: ServiceAccountName specifies a service account name to
be used for this application.
type: string
version:
type: string
required:
Expand Down
3 changes: 3 additions & 0 deletions internal/api/v1beta1/app_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ type AppSpec struct {

// Annotations is a list of annotations that will be applied to Services/Deployments/Gateways.
Annotations []MetadataItem `json:"annotations,omitempty"`

// ServiceAccountName specifies a service account name to be used for this application.
ServiceAccountName string `json:"serviceAccountName,omitempty"`
}

// MetadataItem represent a request to add label/annotations to processes
Expand Down
4 changes: 4 additions & 0 deletions internal/chart/application_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ type app struct {
MetadataLabels []ketchv1.MetadataItem
// MetadataAnnotations is a list of labels to be added to k8s resources.
MetadataAnnotations []ketchv1.MetadataItem `json:"metadataAnnotations"`
// ServiceAccountName specifies a service account name to be used for this application.
// SA should exist.
ServiceAccountName string `json:"serviceAccountName"`
}

type deployment struct {
Expand Down Expand Up @@ -127,6 +130,7 @@ func New(application *ketchv1.App, framework *ketchv1.Framework, opts ...Option)
Group: ketchv1.Group,
MetadataLabels: application.Spec.Labels,
MetadataAnnotations: application.Spec.Annotations,
ServiceAccountName: application.Spec.ServiceAccountName,
},
IngressController: &framework.Spec.IngressController,
}
Expand Down
7 changes: 6 additions & 1 deletion internal/chart/application_chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ func TestNewApplicationChart(t *testing.T) {
},
}

setServiceAccount := func(app *ketchv1.App) *ketchv1.App {
out := *app
out.Spec.ServiceAccountName = "custom-service-account"
return &out
}
// convertSecureEndpoints returns a copy of app with Cnames made not secure
convertSecureEndpoints := func(app *ketchv1.App) *ketchv1.App {
out := *app
Expand Down Expand Up @@ -218,7 +223,7 @@ func TestNewApplicationChart(t *testing.T) {
WithTemplates(templates.NginxDefaultTemplates),
WithExposedPorts(exportedPorts),
},
application: convertSecureEndpoints(dashboard),
application: setServiceAccount(convertSecureEndpoints(dashboard)),
framework: frameworkWithoutClusterIssuer,
wantYamlsFilename: "dashboard-nginx",
},
Expand Down
4 changes: 4 additions & 0 deletions internal/chart/testdata/charts/dashboard-nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ spec:
theketch.io/app-deployment-version: "3"
theketch.io/is-isolated-run: "false"
spec:
serviceAccountName: custom-service-account
containers:
- name: dashboard-web-3
command: ["python"]
Expand Down Expand Up @@ -217,6 +218,7 @@ spec:
theketch.io/app-deployment-version: "3"
theketch.io/is-isolated-run: "false"
spec:
serviceAccountName: custom-service-account
containers:
- name: dashboard-worker-3
command: ["celery"]
Expand Down Expand Up @@ -268,6 +270,7 @@ spec:
theketch.io/app-deployment-version: "4"
theketch.io/is-isolated-run: "false"
spec:
serviceAccountName: custom-service-account
containers:
- name: dashboard-web-4
command: ["python"]
Expand Down Expand Up @@ -318,6 +321,7 @@ spec:
theketch.io/app-deployment-version: "4"
theketch.io/is-isolated-run: "false"
spec:
serviceAccountName: custom-service-account
containers:
- name: dashboard-worker-4
command: ["celery"]
Expand Down
3 changes: 3 additions & 0 deletions internal/templates/common/yamls/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ spec:
{{ $.Values.app.group }}/app-deployment-version: {{ $deployment.version | quote }}
{{ $.Values.app.group }}/is-isolated-run: "false"
spec:
{{- if $.Values.app.serviceAccountName }}
serviceAccountName: {{ $.Values.app.serviceAccountName }}
{{- end }}
containers:
- name: {{ $.Values.app.name }}-{{ $process.name }}-{{ $deployment.version }}
command: {{ $process.cmd | toJson }}
Expand Down