Skip to content

Commit ea00134

Browse files
committed
Update pathconfigs library
implement CRD support and add unit tests Add integration test for crd support address comments
1 parent e7ecceb commit ea00134

19 files changed

+740
-13
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1beta1
2+
kind: Bee
3+
metadata:
4+
name: bee
5+
spec:
6+
action: fly
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
crds:
2+
- mycrd.json
3+
4+
resources:
5+
- secret.yaml
6+
- mykind.yaml
7+
- bee.yaml
8+
9+
namePrefix: test-
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
{
2+
"github.com/example/pkg/apis/jingfang/v1beta1.Bee": {
3+
"Schema": {
4+
"description": "Bee",
5+
"properties": {
6+
"apiVersion": {
7+
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources",
8+
"type": "string"
9+
},
10+
"kind": {
11+
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds",
12+
"type": "string"
13+
},
14+
"metadata": {
15+
"$ref": "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"
16+
},
17+
"spec": {
18+
"$ref": "github.com/example/pkg/apis/jingfang/v1beta1.BeeSpec"
19+
},
20+
"status": {
21+
"$ref": "github.com/example/pkg/apis/jingfang/v1beta1.BeeStatus"
22+
}
23+
}
24+
},
25+
"Dependencies": [
26+
"github.com/example/pkg/apis/jingfang/v1beta1.BeeSpec",
27+
"github.com/example/pkg/apis/jingfang/v1beta1.BeeStatus",
28+
"k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"
29+
]
30+
},
31+
"github.com/example/pkg/apis/jingfang/v1beta1.BeeList": {
32+
"Schema": {
33+
"required": [
34+
"items"
35+
],
36+
"properties": {
37+
"apiVersion": {
38+
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources",
39+
"type": "string"
40+
},
41+
"items": {
42+
"type": "array",
43+
"items": {
44+
"$ref": "github.com/example/pkg/apis/jingfang/v1beta1.Bee"
45+
}
46+
},
47+
"kind": {
48+
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds",
49+
"type": "string"
50+
},
51+
"metadata": {
52+
"$ref": "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"
53+
}
54+
}
55+
},
56+
"Dependencies": [
57+
"github.com/example/pkg/apis/jingfang/v1beta1.Bee",
58+
"k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"
59+
]
60+
},
61+
"github.com/example/pkg/apis/jingfang/v1beta1.BeeObjectReference": {
62+
"Schema": {
63+
"properties": {
64+
"name": {
65+
"type": "string"
66+
}
67+
}
68+
},
69+
"Dependencies": []
70+
},
71+
"github.com/example/pkg/apis/jingfang/v1beta1.BeeSpec": {
72+
"Schema": {
73+
"description": "BeeSpec defines the desired state of Bee"
74+
},
75+
"Dependencies": []
76+
},
77+
"github.com/example/pkg/apis/jingfang/v1beta1.BeeStatus": {
78+
"Schema": {
79+
"description": "BeeStatus defines the observed state of Bee"
80+
},
81+
"Dependencies": []
82+
},
83+
"github.com/example/pkg/apis/jingfang/v1beta1.MyKind": {
84+
"Schema": {
85+
"description": "MyKind",
86+
"properties": {
87+
"apiVersion": {
88+
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources",
89+
"type": "string"
90+
},
91+
"kind": {
92+
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds",
93+
"type": "string"
94+
},
95+
"metadata": {
96+
"$ref": "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"
97+
},
98+
"spec": {
99+
"$ref": "github.com/example/pkg/apis/jingfang/v1beta1.MyKindSpec"
100+
},
101+
"status": {
102+
"$ref": "github.com/example/pkg/apis/jingfang/v1beta1.MyKindStatus"
103+
}
104+
}
105+
},
106+
"Dependencies": [
107+
"github.com/example/pkg/apis/jingfang/v1beta1.MyKindSpec",
108+
"github.com/example/pkg/apis/jingfang/v1beta1.MyKindStatus",
109+
"k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"
110+
]
111+
},
112+
"github.com/example/pkg/apis/jingfang/v1beta1.MyKindList": {
113+
"Schema": {
114+
"required": [
115+
"items"
116+
],
117+
"properties": {
118+
"apiVersion": {
119+
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources",
120+
"type": "string"
121+
},
122+
"items": {
123+
"type": "array",
124+
"items": {
125+
"$ref": "github.com/example/pkg/apis/jingfang/v1beta1.MyKind"
126+
}
127+
},
128+
"kind": {
129+
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds",
130+
"type": "string"
131+
},
132+
"metadata": {
133+
"$ref": "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"
134+
}
135+
}
136+
},
137+
"Dependencies": [
138+
"github.com/example/pkg/apis/jingfang/v1beta1.MyKind",
139+
"k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"
140+
]
141+
},
142+
"github.com/example/pkg/apis/jingfang/v1beta1.MyKindSpec": {
143+
"Schema": {
144+
"description": "MyKindSpec defines the desired state of MyKind",
145+
"properties": {
146+
"beeRef": {
147+
"x-kubernetes-object-ref-api-version": "v1beta1",
148+
"x-kubernetes-object-ref-kind": "Bee",
149+
"$ref": "github.com/example/pkg/apis/jingfang/v1beta1.BeeObjectReference"
150+
},
151+
"secretRef": {
152+
"description": "If defined, we use this secret for configuring the MYSQL_ROOT_PASSWORD If it is not set we generate a secret dynamically",
153+
"x-kubernetes-object-ref-api-version": "v1",
154+
"x-kubernetes-object-ref-kind": "Secret",
155+
"$ref": "k8s.io/api/core/v1.LocalObjectReference"
156+
}
157+
}
158+
},
159+
"Dependencies": [
160+
"github.com/example/pkg/apis/jingfang/v1beta1.BeeObjectReference",
161+
"k8s.io/api/core/v1.LocalObjectReference"
162+
]
163+
},
164+
"github.com/example/pkg/apis/jingfang/v1beta1.MyKindStatus": {
165+
"Schema": {
166+
"description": "MyKindStatus defines the observed state of MyKind"
167+
},
168+
"Dependencies": []
169+
}
170+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: jingfang.example.com/v1beta1
2+
kind: MyKind
3+
metadata:
4+
name: mykind
5+
spec:
6+
secretRef:
7+
name: crdsecret
8+
beeRef:
9+
name: bee
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: crdsecret
5+
data:
6+
PATH: YmJiYmJiYmIK
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
diff -u -N /tmp/noop/jingfang.example.com_v1beta1_MyKind_mykind.yaml /tmp/transformed/jingfang.example.com_v1beta1_MyKind_mykind.yaml
2+
--- /tmp/noop/jingfang.example.com_v1beta1_MyKind_mykind.yaml YYYY-MM-DD HH:MM:SS
3+
+++ /tmp/transformed/jingfang.example.com_v1beta1_MyKind_mykind.yaml YYYY-MM-DD HH:MM:SS
4+
@@ -1,9 +1,9 @@
5+
apiVersion: jingfang.example.com/v1beta1
6+
kind: MyKind
7+
metadata:
8+
- name: mykind
9+
+ name: test-mykind
10+
spec:
11+
beeRef:
12+
- name: bee
13+
+ name: test-bee
14+
secretRef:
15+
- name: crdsecret-m5ht5thcb4
16+
+ name: test-crdsecret-m48btmkck5
17+
diff -u -N /tmp/noop/v1beta1_Bee_bee.yaml /tmp/transformed/v1beta1_Bee_bee.yaml
18+
--- /tmp/noop/v1beta1_Bee_bee.yaml YYYY-MM-DD HH:MM:SS
19+
+++ /tmp/transformed/v1beta1_Bee_bee.yaml YYYY-MM-DD HH:MM:SS
20+
@@ -1,6 +1,6 @@
21+
apiVersion: v1beta1
22+
kind: Bee
23+
metadata:
24+
- name: bee
25+
+ name: test-bee
26+
spec:
27+
action: fly
28+
diff -u -N /tmp/noop/v1_Secret_crdsecret.yaml /tmp/transformed/v1_Secret_crdsecret.yaml
29+
--- /tmp/noop/v1_Secret_crdsecret.yaml YYYY-MM-DD HH:MM:SS
30+
+++ /tmp/transformed/v1_Secret_crdsecret.yaml YYYY-MM-DD HH:MM:SS
31+
@@ -3,4 +3,4 @@
32+
PATH: YmJiYmJiYmIK
33+
kind: Secret
34+
metadata:
35+
- name: crdsecret-m5ht5thcb4
36+
+ name: test-crdsecret-m48btmkck5
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: v1
2+
data:
3+
PATH: YmJiYmJiYmIK
4+
kind: Secret
5+
metadata:
6+
name: test-crdsecret-m48btmkck5
7+
---
8+
apiVersion: v1beta1
9+
kind: Bee
10+
metadata:
11+
name: test-bee
12+
spec:
13+
action: fly
14+
---
15+
apiVersion: jingfang.example.com/v1beta1
16+
kind: MyKind
17+
metadata:
18+
name: test-mykind
19+
spec:
20+
beeRef:
21+
name: test-bee
22+
secretRef:
23+
name: test-crdsecret-m48btmkck5
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
description: name reference in CRDs
2+
args: []
3+
filename: testdata/testcase-crds/crd
4+
expectedStdout: testdata/testcase-crds/expected.yaml
5+
expectedDiff: testdata/testcase-crds/expected.diff

pkg/crds/constants.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2018 The Kubernetes 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 read in files for CRD schemas and parse annotations from it
18+
package crds
19+
20+
// Annotation is to mark a field as annotations.
21+
// "x-kubernetes-annotation": ""
22+
const Annotation = "x-kubernetes-annotation"
23+
24+
// LabelSelector is to mark a field as LabelSelector
25+
// "x-kubernetes-label-selector": ""
26+
const LabelSelector = "x-kubernetes-label-selector"
27+
28+
// Identity is to mark a field as Identity
29+
// "x-kubernetes-identity": ""
30+
const Identity = "x-kubernetes-identity"
31+
32+
// Version marks the type version of an object ref field
33+
// "x-kubernetes-object-ref-api-version": <apiVersion name>
34+
const Version = "x-kubernetes-object-ref-api-version"
35+
36+
// Kind marks the type name of an object ref field
37+
// "x-kubernetes-object-ref-kind": <kind name>
38+
const Kind = "x-kubernetes-object-ref-kind"
39+
40+
// NameKey marks the field key that refers to an object of an object ref field
41+
// "x-kubernetes-object-ref-name-key": "name"
42+
// default is "name"
43+
const NameKey = "x-kubernetes-object-ref-name-key"

0 commit comments

Comments
 (0)