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

Shipa 1573 #232

Merged
merged 4 commits into from
Mar 7, 2022
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
3 changes: 3 additions & 0 deletions internal/api/v1beta1/app_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ type AppSpec struct {

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

// SecurityContext specifies security settings for a pod/app, which get applied to all containers.
SecurityContext *v1.PodSecurityContext `json:"securityContext,omitempty"`
}

// MetadataItem represent a request to add label/annotations to processes
Expand Down
6 changes: 6 additions & 0 deletions internal/chart/application_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type app struct {
// ServiceAccountName specifies a service account name to be used for this application.
// SA should exist.
ServiceAccountName string `json:"serviceAccountName"`
// SecurityContext specifies security settings for a pod/app, which get applied to all containers.
SecurityContext *v1.PodSecurityContext `json:"securityContext,omitempty"`
}

type deployment struct {
Expand Down Expand Up @@ -135,6 +137,10 @@ func New(application *ketchv1.App, framework *ketchv1.Framework, opts ...Option)
IngressController: &framework.Spec.IngressController,
}

if application.Spec.SecurityContext != nil {
values.App.SecurityContext = application.Spec.SecurityContext
}

for _, deploymentSpec := range application.Spec.Deployments {
deployment := deployment{
Image: deploymentSpec.Image,
Expand Down
20 changes: 20 additions & 0 deletions internal/chart/application_chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ func TestNewApplicationChart(t *testing.T) {
}
return &out
}
setPodSecurityContext := func(app *ketchv1.App) *ketchv1.App {
out := *app
fsGroup := int64(2000)
runAsUser := int64(3000)
out.Spec.SecurityContext = &v1.PodSecurityContext{
FSGroup: &fsGroup,
RunAsUser: &runAsUser,
}
return &out
}

tests := []struct {
name string
Expand Down Expand Up @@ -267,6 +277,16 @@ func TestNewApplicationChart(t *testing.T) {
framework: frameworkWithClusterIssuer,
wantYamlsFilename: "dashboard-istio-cluster-issuer",
},
{
name: "istio templates with cluster issuer and pod security context",
opts: []Option{
WithTemplates(templates.IstioDefaultTemplates),
WithExposedPorts(exportedPorts),
},
application: setPodSecurityContext(dashboard),
framework: frameworkWithClusterIssuer,
wantYamlsFilename: "dashboard-istio-cluster-issuer-pod-security-context",
},
{
name: "istio templates without cluster issuer",
opts: []Option{
Expand Down
Loading