Skip to content

Commit

Permalink
added PodSecurityContext
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket-0510 committed Feb 20, 2024
1 parent e0a8a28 commit a3f6e06
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
27 changes: 12 additions & 15 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,19 @@ func newCreateConfig(cmd *cobra.Command, args []string, newClient ClientFactory)
dirName string
absolutePath string
)
client, done := newClient(ClientConfig{Verbose: cfg.Verbose})
defer done()

if len(args) >= 1 {
// IN confirm mode. If also in an interactive terminal, run prompts.
if len(args)<1 {
createdCfg, err := cfg.prompt(client)
if err != nil {
return createdCfg, err
}
fmt.Println("Command:")
fmt.Println(singleCommand(cmd, args, createdCfg))
return createdCfg, nil
}else {
path = args[0]
}

Expand All @@ -206,20 +217,6 @@ func newCreateConfig(cmd *cobra.Command, args []string, newClient ClientFactory)

// Create a tempoarary client for use by the following prompts to complete
// runtime/template suggestions etc
client, done := newClient(ClientConfig{Verbose: cfg.Verbose})
defer done()

// IN confirm mode. If also in an interactive terminal, run prompts.
if interactiveTerminal() {
createdCfg, err := cfg.prompt(client)
if err != nil {
return createdCfg, err
}
fmt.Println("Command:")
fmt.Println(singleCommand(cmd, args, createdCfg))
return createdCfg, nil
}

// Confirming, but noninteractive
// Print out the final values as a confirmation. Only show Repository or
// Repositories, not both (repository takes precedence) in order to avoid
Expand Down
4 changes: 3 additions & 1 deletion pkg/functions/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ type RunSpec struct {

// Env variables to be set
Envs Envs `yaml:"envs,omitempty"`


Check failure on line 144 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

[trailing whitespace] reported by reviewdog 🐶 Raw Output: pkg/functions/function.go:144:
// PodSecurityContext to be set for read and write permission
PodSecurityContext PodSecurityContext `yaml:"podSecurityContext, omitempty"`

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / Check Schema (ubuntu-latest)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / Func Embedded FS Test (ubuntu-latest)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / analyze / Go vulnerability Detection

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / Check Source (ubuntu-latest)

undefined: PodSecurityContext) (typecheck)

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / Check Source (ubuntu-latest)

undefined: PodSecurityContext) (typecheck)

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / Check Source (ubuntu-latest)

undefined: PodSecurityContext) (typecheck)

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / build / Build

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / test / Unit Tests

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / test / Unit Tests

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / Unit Test (21, ubuntu-latest)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / Unit Test (21, ubuntu-latest)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / E2E Test (ubuntu-latest)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / On Cluster Test (ubuntu-latest)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / On Cluster RT Test (ubuntu-latest, pack)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / On Cluster RT Test (ubuntu-latest, s2i)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / E2E Test (rust)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / E2E Test (quarkus)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / Podman Test (ubuntu-latest)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / Podman Test (ubuntu-latest)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / E2E Test (python)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / E2E Test (node)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / Integration Test (ubuntu-latest)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / E2E Test (typescript)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / E2E Test (springboot)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / E2E Test (go)

undefined: PodSecurityContext

Check failure on line 146 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / analyze / Analyze CodeQL

undefined: PodSecurityContext
// StartTimeout specifies that this function should have a custom timeout
// when starting. This setting is currently respected by the host runner,
// with containerized docker runner and deployed Knative service integration
Expand Down
13 changes: 12 additions & 1 deletion pkg/knative/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func generateNewService(f fn.Function, decorator DeployDecorator) (*v1.Service,
for k, v := range annotations {
revisionAnnotations[k] = v
}

PodSecurityContext := getPodSecurityContext(f.Run)
service := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: f.Name,
Expand All @@ -451,6 +451,7 @@ func generateNewService(f fn.Function, decorator DeployDecorator) (*v1.Service,
},
Spec: v1.RevisionSpec{
PodSpec: corev1.PodSpec{
SecurityContext: PodSecurityContext,
Containers: []corev1.Container{
container,
},
Expand Down Expand Up @@ -1075,3 +1076,13 @@ func setServiceOptions(template *v1.RevisionTemplateSpec, options fn.Options) er

return servingclientlib.UpdateRevisionTemplateAnnotations(template, toUpdate, toRemove)
}

func getPodSecurityContext(RunSpec fn.RunSpec) *corev1.PodSecurityContext{
return &corev1.PodSecurityContext{
RunAsUser: RunSpec.PodSecurityContext.RunAsUser,
RunAsGroup: RunSpec.PodSecurityContext.RunAsGroup,
RunAsNonRoot: RunSpec.PodSecurityContext.RunAsNonRoot,
FSGroup: RunSpec.PodSecurityContext.FSGroup,
}

}

Check failure on line 1088 in pkg/knative/deployer.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

[EOF Newline] reported by reviewdog 🐶 Missing newline Raw Output: pkg/knative/deployer.go:1088: Missing newline
22 changes: 21 additions & 1 deletion schema/func_yaml-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
},
"type": "object",
"description": "BuilderImages define optional explicit builder images to use by\nbuilder implementations in leau of the in-code defaults. They key\nis the builder's short name. For example:\nbuilderImages:\n pack: example.com/user/my-pack-node-builder\n s2i: example.com/user/my-s2i-node-builder"
"description// with containerized docker runner and deployed Knative service integration": "BuilderImages define optional explicit builder images to use by\nbuilder implementations in leau of the in-code defaults. They key\nis the builder's short name. For example:\nbuilderImages:\n pack: example.com/user/my-pack-node-builder\n s2i: example.com/user/my-s2i-node-builder"
},
"buildpacks": {
"items": {
Expand Down Expand Up @@ -352,6 +352,26 @@
"type": "array",
"description": "Env variables to be set"
},
"podSecurityContext": {
"properties": {
"RunAsUser": {
"pattern": "^[-._a-zA-Z][-._a-zA-Z0-9]*$",
"type": "integer"
},
"RunAsGroup": {
"type": "integer"
},
"RunAsNonRoot":{
"type": "boolean"
},
"FSGroup":{
"type":"integer"
}
},
"additionalProperties": false,
"type": "object"

Check failure on line 373 in schema/func_yaml-schema.json

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

[trailing whitespace] reported by reviewdog 🐶 Raw Output: schema/func_yaml-schema.json:373:
},
"startTimeout": {
"type": "integer",
"description": "StartTimeout specifies that this function should have a custom timeout\nwhen starting. This setting is currently respected by the host runner,\nwith containerized docker runner and deployed Knative service integration\nin development."
Expand Down

0 comments on commit a3f6e06

Please sign in to comment.