Skip to content

Commit 4c210f0

Browse files
committed
feat(operators): add v2alpha1 operator types
Add the v2alpha1 group version and the initial Operator type definition. In this form, the Operator type will support aggregating resource status conditions to enable operator component discoverability.
1 parent d9f7449 commit 4c210f0

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
15+
// Package v2alpha1 contains API Schema definitions for the discovery v2alpha1 API group.
16+
// +kubebuilder:object:generate=true
17+
// +groupName=operators.coreos.com
18+
package v2alpha1
19+
20+
import (
21+
"k8s.io/apimachinery/pkg/runtime/schema"
22+
"sigs.k8s.io/controller-runtime/pkg/scheme"
23+
)
24+
25+
var (
26+
// GroupVersion is group version used to register these objects.
27+
GroupVersion = schema.GroupVersion{Group: "operators.coreos.com", Version: "v2alpha1"}
28+
29+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
30+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
31+
32+
// AddToScheme adds the types in this group-version to the given scheme.
33+
AddToScheme = SchemeBuilder.AddToScheme
34+
)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
package v2alpha1
17+
18+
import (
19+
corev1 "k8s.io/api/core/v1"
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// OperatorSpec defines the desired state of Operator
24+
type OperatorSpec struct{}
25+
26+
// OperatorStatus describes the observed state of an operator and its components.
27+
type OperatorStatus struct {
28+
// Components describes resources that compose the operator.
29+
// +optional
30+
Components *Components `json:"components,omitempty"`
31+
}
32+
33+
// ConditionType codifies a condition's type.
34+
type ConditionType string
35+
36+
// Condition represent the latest available observations of an component's state.
37+
type Condition struct {
38+
// Type of condition.
39+
Type ConditionType `json:"type"`
40+
// Status of the condition, one of True, False, Unknown.
41+
Status corev1.ConditionStatus `json:"status"`
42+
// The reason for the condition's last transition.
43+
// +optional
44+
Reason string `json:"reason,omitempty"`
45+
// A human readable message indicating details about the transition.
46+
// +optional
47+
Message string `json:"message,omitempty"`
48+
// Last time the condition was probed
49+
// +optional
50+
LastUpdateTime *metav1.Time `json:"lastUpdateTime,omitempty"`
51+
// Last time the condition transitioned from one status to another.
52+
// +optional
53+
LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty"`
54+
}
55+
56+
// Components tracks the resources that compose an operator.
57+
type Components struct {
58+
// LabelSelector is a label query over a set of resources used to select the operator's components
59+
LabelSelector *metav1.LabelSelector `json:"labelSelector"`
60+
// Refs are a set of references to the operator's component resources, selected with LabelSelector.
61+
// +optional
62+
Refs []RichReference `json:"refs,omitempty"`
63+
}
64+
65+
// RichReference is a reference to a resource, enriched with its status conditions.
66+
type RichReference struct {
67+
*corev1.ObjectReference `json:",inline"`
68+
// Conditions represents the latest state of the component.
69+
// +optional
70+
// +patchMergeKey=type
71+
// +patchStrategy=merge
72+
Conditions []Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
73+
}
74+
75+
// +kubebuilder:object:root=true
76+
// +kubebuilder:resource:scope=Cluster
77+
// +kubebuilder:storageversion
78+
79+
// Operator represents a cluster operator.
80+
type Operator struct {
81+
metav1.TypeMeta `json:",inline"`
82+
metav1.ObjectMeta `json:"metadata,omitempty"`
83+
84+
Spec OperatorSpec `json:"spec,omitempty"`
85+
Status OperatorStatus `json:"status,omitempty"`
86+
}
87+
88+
// +kubebuilder:object:root=true
89+
90+
// OperatorList contains a list of Operators.
91+
type OperatorList struct {
92+
metav1.TypeMeta `json:",inline"`
93+
metav1.ListMeta `json:"metadata,omitempty"`
94+
Items []Operator `json:"items"`
95+
}
96+
97+
func init() {
98+
SchemeBuilder.Register(&Operator{}, &OperatorList{})
99+
}

0 commit comments

Comments
 (0)