Change api version in generate command
Changing api version in generate command since it was outdated v1alpha2. The following changes took place: * duplicated v1alpha2 package to v1 to avoid confusion * updated examples to point to the right version * updated default value to be v1 instead of v1alpha2 * fixed a bug where default namespace is unset Signed-off-by: Martin Dekov <mvdekov@gmail.com>
This commit is contained in:
		| @@ -12,7 +12,7 @@ import ( | ||||
| 	"github.com/openfaas/faas-cli/proxy" | ||||
| 	"github.com/openfaas/faas-cli/schema" | ||||
| 	knativev1alpha1 "github.com/openfaas/faas-cli/schema/knative/v1alpha1" | ||||
| 	openfaasv1alpha2 "github.com/openfaas/faas-cli/schema/openfaas/v1alpha2" | ||||
| 	openfaasv1 "github.com/openfaas/faas-cli/schema/openfaas/v1" | ||||
| 	"github.com/openfaas/faas-cli/stack" | ||||
| 	"github.com/pkg/errors" | ||||
| 	"github.com/spf13/cobra" | ||||
| @@ -22,7 +22,7 @@ import ( | ||||
| const ( | ||||
| 	defaultFunctionNamespace = "openfaas-fn" | ||||
| 	resourceKind             = "Function" | ||||
| 	defaultAPIVersion        = "openfaas.com/v1alpha2" | ||||
| 	defaultAPIVersion        = "openfaas.com/v1" | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| @@ -48,14 +48,14 @@ func init() { | ||||
| } | ||||
|  | ||||
| var generateCmd = &cobra.Command{ | ||||
| 	Use:   "generate --api=openfaas.com/v1alpha2 --yaml stack.yml --tag sha --namespace=openfaas-fn", | ||||
| 	Use:   "generate --api=openfaas.com/v1 --yaml stack.yml --tag sha --namespace=openfaas-fn", | ||||
| 	Short: "Generate Kubernetes CRD YAML file", | ||||
| 	Long:  `The generate command creates kubernetes CRD YAML file for functions`, | ||||
| 	Example: `faas-cli generate --api=openfaas.com/v1alpha2 --yaml stack.yml | kubectl apply  -f - | ||||
| faas-cli generate --api=openfaas.com/v1alpha2 -f stack.yml | ||||
| 	Example: `faas-cli generate --api=openfaas.com/v1 --yaml stack.yml | kubectl apply  -f - | ||||
| faas-cli generate --api=openfaas.com/v1 -f stack.yml | ||||
| faas-cli generate --api=serving.knative.dev/v1alpha1 -f stack.yml | ||||
| faas-cli generate --api=openfaas.com/v1alpha2 --namespace openfaas-fn -f stack.yml | ||||
| faas-cli generate --api=openfaas.com/v1alpha2 -f stack.yml --tag branch -n openfaas-fn`, | ||||
| faas-cli generate --api=openfaas.com/v1 --namespace openfaas-fn -f stack.yml | ||||
| faas-cli generate --api=openfaas.com/v1 -f stack.yml --tag branch -n openfaas-fn`, | ||||
| 	PreRunE: preRunGenerate, | ||||
| 	RunE:    runGenerate, | ||||
| } | ||||
| @@ -96,6 +96,10 @@ func runGenerate(cmd *cobra.Command, args []string) error { | ||||
| 		return fmt.Errorf("error parsing annotations: %v", annotationErr) | ||||
| 	} | ||||
|  | ||||
| 	if len(functionNamespace) == 0 { | ||||
| 		functionNamespace = defaultFunctionNamespace | ||||
| 	} | ||||
|  | ||||
| 	if len(fromStore) > 0 { | ||||
| 		services = stack.Services{ | ||||
| 			Provider: stack.Provider{ | ||||
| @@ -190,7 +194,7 @@ func generateCRDYAML(services stack.Services, format schema.BuildFormat, apiVers | ||||
| 			metadata := schema.Metadata{Name: name, Namespace: namespace} | ||||
| 			imageName := schema.BuildImageName(format, function.Image, version, branch) | ||||
|  | ||||
| 			spec := openfaasv1alpha2.Spec{ | ||||
| 			spec := openfaasv1.Spec{ | ||||
| 				Name:        name, | ||||
| 				Image:       imageName, | ||||
| 				Environment: allEnvironment, | ||||
| @@ -201,7 +205,7 @@ func generateCRDYAML(services stack.Services, format schema.BuildFormat, apiVers | ||||
| 				Secrets:     function.Secrets, | ||||
| 			} | ||||
|  | ||||
| 			crd := openfaasv1alpha2.CRD{ | ||||
| 			crd := openfaasv1.CRD{ | ||||
| 				APIVersion: apiVersion, | ||||
| 				Kind:       resourceKind, | ||||
| 				Metadata:   metadata, | ||||
|   | ||||
							
								
								
									
										45
									
								
								schema/openfaas/v1/crd.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								schema/openfaas/v1/crd.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,45 @@ | ||||
| // Copyright (c) OpenFaaS Author(s) 2018. All rights reserved. | ||||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||||
|  | ||||
| package v1 | ||||
|  | ||||
| import ( | ||||
| 	"github.com/openfaas/faas-cli/schema" | ||||
| 	"github.com/openfaas/faas-cli/stack" | ||||
| ) | ||||
|  | ||||
| //APIVersionLatest latest API version of CRD | ||||
| const APIVersionLatest = "openfaas.com/v1" | ||||
|  | ||||
| //Spec describe characteristics of the object | ||||
| type Spec struct { | ||||
| 	//Name name of the function | ||||
| 	Name string `yaml:"name"` | ||||
| 	//Image docker image name of the function | ||||
| 	Image string `yaml:"image"` | ||||
|  | ||||
| 	Environment map[string]string `yaml:"environment,omitempty"` | ||||
|  | ||||
| 	Labels *map[string]string `yaml:"labels,omitempty"` | ||||
|  | ||||
| 	//Limits for the function | ||||
| 	Limits *stack.FunctionResources `yaml:"limits,omitempty"` | ||||
|  | ||||
| 	//Requests of resources requested by function | ||||
| 	Requests *stack.FunctionResources `yaml:"requests,omitempty"` | ||||
|  | ||||
| 	Constraints *[]string `yaml:"constraints,omitempty"` | ||||
|  | ||||
| 	//Secrets list of secrets to be made available to function | ||||
| 	Secrets []string `yaml:"secrets,omitempty"` | ||||
| } | ||||
|  | ||||
| //CRD root level YAML definition for the object | ||||
| type CRD struct { | ||||
| 	//APIVersion CRD API version | ||||
| 	APIVersion string `yaml:"apiVersion"` | ||||
| 	//Kind kind of the object | ||||
| 	Kind     string          `yaml:"kind"` | ||||
| 	Metadata schema.Metadata `yaml:"metadata"` | ||||
| 	Spec     Spec            `yaml:"spec"` | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Martin Dekov
					Martin Dekov