Skip to content

Commit 54dbef4

Browse files
authored
Add helper library for CRDs (#977)
Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent 16483ce commit 54dbef4

File tree

200 files changed

+256
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+256
-62
lines changed

api/crds/lib.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright The Stash Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package crds
18+
19+
import (
20+
"fmt"
21+
22+
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/yaml"
25+
)
26+
27+
func CustomResourceDefinition(gvr schema.GroupVersionResource) (*apiextensions.CustomResourceDefinition, error) {
28+
data, err := Asset(fmt.Sprintf("%s_%s.yaml", gvr.Group, gvr.Resource))
29+
if err != nil {
30+
return nil, err
31+
}
32+
var out apiextensions.CustomResourceDefinition
33+
err = yaml.Unmarshal(data, &out)
34+
if err != nil {
35+
return nil, err
36+
}
37+
return &out, nil
38+
}
39+
40+
func MustCustomResourceDefinition(gvr schema.GroupVersionResource) *apiextensions.CustomResourceDefinition {
41+
out, err := CustomResourceDefinition(gvr)
42+
if err != nil {
43+
panic(err)
44+
}
45+
return out
46+
}

apis/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
1617
package apis
1718

1819
const (

apis/repositories/v1alpha1/generated.pb.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/repositories/v1alpha1/generated.proto

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/stash/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
1617
package stash
1718

1819
// GroupName is the group name use in this package

apis/stash/v1alpha1/annotations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
1617
package v1alpha1
1718

1819
const (

apis/stash/v1alpha1/generated.pb.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/stash/v1alpha1/generated.proto

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/stash/v1alpha1/recovery_helpers.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
1617
package v1alpha1
1718

1819
import (
1920
"stash.appscode.dev/stash/api/crds"
2021

2122
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
22-
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
23-
"sigs.k8s.io/yaml"
2423
)
2524

2625
func (_ Recovery) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {
27-
data := crds.MustAsset("stash.appscode.com_recoveries.yaml")
28-
var out apiextensions.CustomResourceDefinition
29-
utilruntime.Must(yaml.Unmarshal(data, &out))
30-
return &out
26+
return crds.MustCustomResourceDefinition(SchemeGroupVersion.WithResource(ResourcePluralRecovery))
3127
}

apis/stash/v1alpha1/recovery_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
1617
package v1alpha1
1718

1819
import (

0 commit comments

Comments
 (0)