Refactor openfaas crd generation

This commit refactor openfaas crd schema puts it inside a package with
a version name so that it's easy to add new version for openfaas CRD

Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>
This commit is contained in:
Vivek Singh
2019-05-13 18:45:46 +05:30
committed by Alex Ellis
parent ad548d2696
commit d4c9b6fefc
3 changed files with 23 additions and 12 deletions

View File

@@ -11,6 +11,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"
"github.com/openfaas/faas-cli/stack"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@@ -186,7 +187,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 := schema.Spec{
spec := openfaasv1alpha2.Spec{
Name: name,
Image: imageName,
Environment: allEnvironment,
@@ -197,7 +198,7 @@ func generateCRDYAML(services stack.Services, format schema.BuildFormat, apiVers
Secrets: function.Secrets,
}
crd := schema.CRD{
crd := openfaasv1alpha2.CRD{
APIVersion: apiVersion,
Kind: resourceKind,
Metadata: metadata,

10
schema/metadata.go Normal file
View File

@@ -0,0 +1,10 @@
// 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 schema
//Metadata metadata of the object
type Metadata struct {
Name string `yaml:"name"`
Namespace string `yaml:"namespace,omitempty"`
}

View File

@@ -1,15 +1,15 @@
// 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 schema
package v1alpha2
import "github.com/openfaas/faas-cli/stack"
import (
"github.com/openfaas/faas-cli/schema"
"github.com/openfaas/faas-cli/stack"
)
//Metadata metadata of the object
type Metadata struct {
Name string `yaml:"name"`
Namespace string `yaml:"namespace,omitempty"`
}
//APIVersionLatest latest API version of CRD
const APIVersionLatest = "openfaas.com/v1alpha2"
//Spec describe characteristics of the object
type Spec struct {
@@ -39,7 +39,7 @@ type CRD struct {
//APIVersion CRD API version
APIVersion string `yaml:"apiVersion"`
//Kind kind of the object
Kind string `yaml:"kind"`
Metadata Metadata `yaml:"metadata"`
Spec Spec `yaml:"spec"`
Kind string `yaml:"kind"`
Metadata schema.Metadata `yaml:"metadata"`
Spec Spec `yaml:"spec"`
}