Skip to content

Commit

Permalink
Add CRD Validation (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalsaha authored Mar 31, 2018
1 parent a7351a4 commit 964c6f3
Show file tree
Hide file tree
Showing 16 changed files with 2,139 additions and 86 deletions.
96 changes: 46 additions & 50 deletions apis/stash/v1alpha1/crd.go
Original file line number Diff line number Diff line change
@@ -1,67 +1,63 @@
package v1alpha1

import (
"github.com/appscode/stash/apis/stash"
crdutils "github.com/appscode/kutil/apiextensions/v1beta1"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (c Restic) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {
return &apiextensions.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: ResourceTypeRestic + "." + SchemeGroupVersion.Group,
Labels: map[string]string{"app": "stash"},
return crdutils.NewCustomResourceDefinition(crdutils.Config{
Group: SchemeGroupVersion.Group,
Version: SchemeGroupVersion.Version,
Plural: ResourcePluralRestic,
Singular: ResourceSingularRestic,
Kind: ResourceKindRestic,
ListKind: ResourceKindRestic + "List",
ShortNames: []string{"rst"},
ResourceScope: string(apiextensions.NamespaceScoped),
Labels: crdutils.Labels{
LabelsMap: map[string]string{"app": "stash"},
},
Spec: apiextensions.CustomResourceDefinitionSpec{
Group: stash.GroupName,
Version: SchemeGroupVersion.Version,
Scope: apiextensions.NamespaceScoped,
Names: apiextensions.CustomResourceDefinitionNames{
Singular: ResourceNameRestic,
Plural: ResourceTypeRestic,
Kind: ResourceKindRestic,
ShortNames: []string{"rst"},
},
},
}
SpecDefinitionName: "github.com/appscode/stash/apis/stash/v1alpha1.Restic",
EnableValidation: true,
GetOpenAPIDefinitions: GetOpenAPIDefinitions,
})
}

func (c Recovery) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {
return &apiextensions.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: ResourceTypeRecovery + "." + SchemeGroupVersion.Group,
Labels: map[string]string{"app": "stash"},
},
Spec: apiextensions.CustomResourceDefinitionSpec{
Group: stash.GroupName,
Version: SchemeGroupVersion.Version,
Scope: apiextensions.NamespaceScoped,
Names: apiextensions.CustomResourceDefinitionNames{
Singular: ResourceNameRecovery,
Plural: ResourceTypeRecovery,
Kind: ResourceKindRecovery,
ShortNames: []string{"rec"},
},
return crdutils.NewCustomResourceDefinition(crdutils.Config{
Group: SchemeGroupVersion.Group,
Version: SchemeGroupVersion.Version,
Plural: ResourcePluralRecovery,
Singular: ResourceSingularRecovery,
Kind: ResourceKindRecovery,
ListKind: ResourceKindRecovery + "List",
ShortNames: []string{"rec"},
ResourceScope: string(apiextensions.NamespaceScoped),
Labels: crdutils.Labels{
LabelsMap: map[string]string{"app": "stash"},
},
}
SpecDefinitionName: "github.com/appscode/stash/apis/stash/v1alpha1.Recovery",
EnableValidation: true,
GetOpenAPIDefinitions: GetOpenAPIDefinitions,
})
}

func (c Repository) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {
return &apiextensions.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: ResourceTypeRepository + "." + SchemeGroupVersion.Group,
Labels: map[string]string{"app": "stash"},
},
Spec: apiextensions.CustomResourceDefinitionSpec{
Group: stash.GroupName,
Version: SchemeGroupVersion.Version,
Scope: apiextensions.NamespaceScoped,
Names: apiextensions.CustomResourceDefinitionNames{
Singular: ResourceNameRepository,
Plural: ResourceTypeRepository,
Kind: ResourceKindRepository,
ShortNames: []string{"repo"},
},
return crdutils.NewCustomResourceDefinition(crdutils.Config{
Group: SchemeGroupVersion.Group,
Version: SchemeGroupVersion.Version,
Plural: ResourcePluralRepository,
Singular: ResourceSingularRepository,
Kind: ResourceKindRepository,
ListKind: ResourceKindRepository + "List",
ShortNames: []string{"repo"},
ResourceScope: string(apiextensions.NamespaceScoped),
Labels: crdutils.Labels{
LabelsMap: map[string]string{"app": "stash"},
},
}
SpecDefinitionName: "github.com/appscode/stash/apis/stash/v1alpha1.Repository",
EnableValidation: true,
GetOpenAPIDefinitions: GetOpenAPIDefinitions,
})
}
1,294 changes: 1,290 additions & 4 deletions apis/stash/v1alpha1/crds.yaml

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions apis/stash/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
)

const (
ResourceKindRestic = "Restic"
ResourceNameRestic = "restic"
ResourceTypeRestic = "restics"
ResourceKindRecovery = "Recovery"
ResourceNameRecovery = "recovery"
ResourceTypeRecovery = "recoveries"
ResourceKindRestic = "Restic"
ResourceSingularRestic = "restic"
ResourcePluralRestic = "restics"
ResourceKindRecovery = "Recovery"
ResourceSingularRecovery = "recovery"
ResourcePluralRecovery = "recoveries"
)

// +genclient
Expand Down Expand Up @@ -212,9 +212,9 @@ type RestoreStats struct {
}

const (
ResourceKindRepository = "Repository"
ResourceTypeRepository = "repositories"
ResourceNameRepository = "repository"
ResourceKindRepository = "Repository"
ResourcePluralRepository = "repositories"
ResourceSingularRepository = "repository"
)

// +genclient
Expand Down
10 changes: 5 additions & 5 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions hack/gencrd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"os"

"github.com/appscode/go/log"
"github.com/appscode/go/runtime"
crdutils "github.com/appscode/kutil/apiextensions/v1beta1"
api "github.com/appscode/stash/apis/stash/v1alpha1"
crd_api "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
)

func main() {
filename := runtime.GOPath() + "/src/github.com/appscode/stash/apis/stash/v1alpha1/crds.yaml"

f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
log.Fatal(err)
}
defer f.Close()

crds := []*crd_api.CustomResourceDefinition{
api.Restic{}.CustomResourceDefinition(),
api.Recovery{}.CustomResourceDefinition(),
api.Repository{}.CustomResourceDefinition(),
}
for _, crd := range crds {
crdutils.MarshallCrd(f, crd, "yaml")
}
}
151 changes: 151 additions & 0 deletions vendor/github.com/appscode/kutil/apiextensions/v1beta1/cli-utils.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 964c6f3

Please sign in to comment.