From 0451db85faebbc4b2c9c69c8af64686ff6617825 Mon Sep 17 00:00:00 2001 From: "Han Verstraete (OpenFaaS Ltd)" Date: Tue, 20 Sep 2022 16:09:07 +0200 Subject: [PATCH] Fix generate command for read-only root filesystem setting The readonly_root_filesystem setting was not included in the resulting CRD when running faas-cli generate. Signed-off-by: Han Verstraete (OpenFaaS Ltd) --- commands/generate.go | 19 ++++++++++--------- commands/generate_test.go | 29 +++++++++++++++++++++++++++++ schema/openfaas/v1/crd.go | 2 ++ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/commands/generate.go b/commands/generate.go index be985330..a29435f8 100644 --- a/commands/generate.go +++ b/commands/generate.go @@ -203,15 +203,16 @@ func generateCRDYAML(services stack.Services, format schema.BuildFormat, apiVers imageName := schema.BuildImageName(format, function.Image, version, branch) spec := openfaasv1.Spec{ - Name: name, - Image: imageName, - Environment: allEnvironment, - Labels: function.Labels, - Annotations: function.Annotations, - Limits: function.Limits, - Requests: function.Requests, - Constraints: function.Constraints, - Secrets: function.Secrets, + Name: name, + Image: imageName, + Environment: allEnvironment, + Labels: function.Labels, + Annotations: function.Annotations, + Limits: function.Limits, + Requests: function.Requests, + Constraints: function.Constraints, + Secrets: function.Secrets, + ReadOnlyRootFilesystem: function.ReadOnlyRootFilesystem, } crd := openfaasv1.CRD{ diff --git a/commands/generate_test.go b/commands/generate_test.go index 1edc619a..8bb9e67d 100644 --- a/commands/generate_test.go +++ b/commands/generate_test.go @@ -202,6 +202,35 @@ spec: Branch: "", Version: "", }, + { + Name: "Read-only root filesystem", + Input: ` +provider: + name: openfaas + gateway: http://127.0.0.1:8080 +functions: + url-ping: + lang: python + handler: ./sample/url-ping + image: alexellis/faas-url-ping:0.2 + readonly_root_filesystem: true`, + Output: []string{`--- +apiVersion: openfaas.com/v1 +kind: Function +metadata: + name: url-ping + namespace: openfaas-fn +spec: + name: url-ping + image: alexellis/faas-url-ping:0.2 + readOnlyRootFilesystem: true +`}, + Format: schema.DefaultFormat, + APIVersion: "openfaas.com/v1", + Namespace: "openfaas-fn", + Branch: "", + Version: "", + }, } func Test_generateCRDYAML(t *testing.T) { diff --git a/schema/openfaas/v1/crd.go b/schema/openfaas/v1/crd.go index 5f0cc11b..5f45bd0a 100644 --- a/schema/openfaas/v1/crd.go +++ b/schema/openfaas/v1/crd.go @@ -34,6 +34,8 @@ type Spec struct { //Secrets list of secrets to be made available to function Secrets []string `yaml:"secrets,omitempty"` + + ReadOnlyRootFilesystem bool `yaml:"readOnlyRootFilesystem,omitempty"` } //CRD root level YAML definition for the object