This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
register.go
176 lines (161 loc) · 5.13 KB
/
register.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package v1alpha1
import (
"fmt"
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
apis "code.cloudfoundry.org/quarks-secret/pkg/kube/apis"
"code.cloudfoundry.org/quarks-utils/pkg/pointers"
)
// This file looks almost the same for all controllers
// Modify the addKnownTypes function, then run `make generate`
const (
// QuarksSecretResourceKind is the kind name of QuarksSecret
QuarksSecretResourceKind = "QuarksSecret"
// QuarksSecretResourcePlural is the plural name of QuarksSecret
QuarksSecretResourcePlural = "quarkssecrets"
)
var (
schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
// AddToScheme is used for schema registrations in the controller package
// and also in the generated kube code
AddToScheme = schemeBuilder.AddToScheme
// QuarksSecretResourceShortNames is the short names of QuarksSecret
QuarksSecretResourceShortNames = []string{"qsec", "qsecs"}
// QuarksSecretValidation is the validation schema for QuarksSecret
QuarksSecretValidation = extv1.CustomResourceValidation{
OpenAPIV3Schema: &extv1.JSONSchemaProps{
Type: "object",
Properties: map[string]extv1.JSONSchemaProps{
"spec": {
Type: "object",
Properties: map[string]extv1.JSONSchemaProps{
"secretName": {
Type: "string",
MinLength: pointers.Int64(1),
Description: "The name of the generated secret",
},
"type": {
Type: "string",
MinLength: pointers.Int64(1),
Description: "What kind of secret to generate: password, certificate, ssh, rsa",
},
"request": {
Type: "object",
XPreserveUnknownFields: pointers.Bool(true),
Properties: map[string]extv1.JSONSchemaProps{
"templatedConfig": {
Type: "object",
Description: "TemplatedConfig renders the template map into the generated secret",
Properties: map[string]extv1.JSONSchemaProps{
"type": {
Type: "string",
Description: "Type of template being used (helm)",
},
"templates": {
Type: "object",
XPreserveUnknownFields: pointers.Bool(true),
Description: "Template values to interpolate in the generated secret",
},
"values": {
Type: "object",
XPreserveUnknownFields: pointers.Bool(true),
Description: "Template values to interpolate in the generated secret",
},
},
},
},
},
"copies": {
Type: "array",
Description: "A list of namespaced names where to copy generated secrets",
Items: &extv1.JSONSchemaPropsOrArray{
Schema: &extv1.JSONSchemaProps{
Type: "object",
XPreserveUnknownFields: pointers.Bool(true),
},
},
},
"secretLabels": {
Type: "object",
XPreserveUnknownFields: pointers.Bool(true),
},
"secretAnnotations": {
Type: "object",
XPreserveUnknownFields: pointers.Bool(true),
},
},
Required: []string{
"secretName",
"type",
},
},
"status": {
Type: "object",
Properties: map[string]extv1.JSONSchemaProps{
"generated": {
Type: "boolean",
},
"copied": {
Type: "boolean",
},
"lastReconcile": {
Type: "string",
Nullable: true,
},
},
},
},
},
}
// QuarksSecretAdditionalPrinterColumns are used by `kubectl get`
QuarksSecretAdditionalPrinterColumns = []extv1.CustomResourceColumnDefinition{
{
Name: "type",
Type: "string",
JSONPath: ".spec.type",
},
{
Name: "copied",
Type: "boolean",
JSONPath: ".status.copied",
},
{
Name: "generated",
Type: "boolean",
JSONPath: ".status.generated",
},
{
Name: "age",
Type: "date",
JSONPath: ".metadata.creationTimestamp",
},
{
Name: "reconcile",
Type: "date",
JSONPath: ".status.lastReconcile",
},
}
// QuarksSecretResourceName is the resource name of QuarksSecret
QuarksSecretResourceName = fmt.Sprintf("%s.%s", QuarksSecretResourcePlural, apis.GroupName)
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: apis.GroupName, Version: "v1alpha1"}
)
// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
// Adds the list of known types to Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&QuarksSecret{},
&QuarksSecretList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}