Skip to content

Commit 6c5b247

Browse files
tmshortawgreene
authored andcommitted
Initial kubebuilder create api
`kubebuilder create api --group operators --version v1alpha1 --kind Operator` Signed-off-by: Todd Short <[email protected]>
1 parent 0602cea commit 6c5b247

17 files changed

+519
-0
lines changed

PROJECT

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,14 @@ layout:
33
- go.kubebuilder.io/v4-alpha
44
projectName: operator-controller
55
repo: github.com/operator-framework/operator-controller
6+
resources:
7+
- api:
8+
crdVersion: v1
9+
namespaced: true
10+
controller: true
11+
domain: operatorframework.io
12+
group: operators
13+
kind: Operator
14+
path: github.com/operator-framework/operator-controller/api/v1alpha1
15+
version: v1alpha1
616
version: "3"

api/v1alpha1/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2022.
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 v1alpha1 contains API Schema definitions for the operators v1alpha1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=operators.operatorframework.io
20+
package v1alpha1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "operators.operatorframework.io", Version: "v1alpha1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

api/v1alpha1/operator_types.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2022.
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 v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25+
26+
// OperatorSpec defines the desired state of Operator
27+
type OperatorSpec struct {
28+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29+
// Important: Run "make" to regenerate code after modifying this file
30+
31+
// Foo is an example field of Operator. Edit operator_types.go to remove/update
32+
Foo string `json:"foo,omitempty"`
33+
}
34+
35+
// OperatorStatus defines the observed state of Operator
36+
type OperatorStatus struct {
37+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38+
// Important: Run "make" to regenerate code after modifying this file
39+
}
40+
41+
//+kubebuilder:object:root=true
42+
//+kubebuilder:subresource:status
43+
44+
// Operator is the Schema for the operators API
45+
type Operator struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ObjectMeta `json:"metadata,omitempty"`
48+
49+
Spec OperatorSpec `json:"spec,omitempty"`
50+
Status OperatorStatus `json:"status,omitempty"`
51+
}
52+
53+
//+kubebuilder:object:root=true
54+
55+
// OperatorList contains a list of Operator
56+
type OperatorList struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ListMeta `json:"metadata,omitempty"`
59+
Items []Operator `json:"items"`
60+
}
61+
62+
func init() {
63+
SchemeBuilder.Register(&Operator{}, &OperatorList{})
64+
}

api/v1alpha1/zz_generated.deepcopy.go

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

config/crd/kustomization.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This kustomization.yaml is not intended to be run by itself,
2+
# since it depends on service name and namespace that are out of this kustomize package.
3+
# It should be run by config/default
4+
resources:
5+
- bases/operators.operatorframework.io_operators.yaml
6+
#+kubebuilder:scaffold:crdkustomizeresource
7+
8+
patchesStrategicMerge:
9+
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
10+
# patches here are for enabling the conversion webhook for each CRD
11+
#- patches/webhook_in_operators.yaml
12+
#+kubebuilder:scaffold:crdkustomizewebhookpatch
13+
14+
# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
15+
# patches here are for enabling the CA injection for each CRD
16+
#- patches/cainjection_in_operators.yaml
17+
#+kubebuilder:scaffold:crdkustomizecainjectionpatch
18+
19+
# the following config is for teaching kustomize how to do kustomization for CRDs.
20+
configurations:
21+
- kustomizeconfig.yaml

config/crd/kustomizeconfig.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file is for teaching kustomize how to substitute name and namespace reference in CRD
2+
nameReference:
3+
- kind: Service
4+
version: v1
5+
fieldSpecs:
6+
- kind: CustomResourceDefinition
7+
version: v1
8+
group: apiextensions.k8s.io
9+
path: spec/conversion/webhook/clientConfig/service/name
10+
11+
namespace:
12+
- kind: CustomResourceDefinition
13+
version: v1
14+
group: apiextensions.k8s.io
15+
path: spec/conversion/webhook/clientConfig/service/namespace
16+
create: false
17+
18+
varReference:
19+
- path: metadata/annotations
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# The following patch adds a directive for certmanager to inject CA into the CRD
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
cert-manager.io/inject-ca-from: CERTIFICATE_NAMESPACE/CERTIFICATE_NAME
7+
name: operators.operators.operatorframework.io
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# The following patch enables a conversion webhook for the CRD
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
name: operators.operators.operatorframework.io
6+
spec:
7+
conversion:
8+
strategy: Webhook
9+
webhook:
10+
clientConfig:
11+
service:
12+
namespace: system
13+
name: webhook-service
14+
path: /convert
15+
conversionReviewVersions:
16+
- v1

config/rbac/operator_editor_role.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# permissions for end users to edit operators.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
labels:
6+
app.kubernetes.io/name: clusterrole
7+
app.kubernetes.io/instance: operator-editor-role
8+
app.kubernetes.io/component: rbac
9+
app.kubernetes.io/created-by: operator-controller
10+
app.kubernetes.io/part-of: operator-controller
11+
app.kubernetes.io/managed-by: kustomize
12+
name: operator-editor-role
13+
rules:
14+
- apiGroups:
15+
- operators.operatorframework.io
16+
resources:
17+
- operators
18+
verbs:
19+
- create
20+
- delete
21+
- get
22+
- list
23+
- patch
24+
- update
25+
- watch
26+
- apiGroups:
27+
- operators.operatorframework.io
28+
resources:
29+
- operators/status
30+
verbs:
31+
- get

config/rbac/operator_viewer_role.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# permissions for end users to view operators.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
labels:
6+
app.kubernetes.io/name: clusterrole
7+
app.kubernetes.io/instance: operator-viewer-role
8+
app.kubernetes.io/component: rbac
9+
app.kubernetes.io/created-by: operator-controller
10+
app.kubernetes.io/part-of: operator-controller
11+
app.kubernetes.io/managed-by: kustomize
12+
name: operator-viewer-role
13+
rules:
14+
- apiGroups:
15+
- operators.operatorframework.io
16+
resources:
17+
- operators
18+
verbs:
19+
- get
20+
- list
21+
- watch
22+
- apiGroups:
23+
- operators.operatorframework.io
24+
resources:
25+
- operators/status
26+
verbs:
27+
- get

0 commit comments

Comments
 (0)