Skip to content

Commit 085f869

Browse files
authored
Create V1 API (#461)
* Create V1 API * Update tests to v1 * Update project file * Add v1 sample to CSV * use kubectl create
1 parent 6f09d18 commit 085f869

File tree

188 files changed

+21346
-721
lines changed

Some content is hidden

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

188 files changed

+21346
-721
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Current Operator version.
2-
VERSION ?= 0.8.1
2+
VERSION ?= 1.0.0
33
OPERATOR_SDK_RELEASE_VERSION ?= v1.24.0
44

55
# CHANNELS define the bundle channels used in the bundle.

PROJECT

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ layout: go.kubebuilder.io/v3
22
projectName: runtime-component
33
repo: github.com/application-stacks/runtime-component-operator
44
resources:
5+
- group: rc.app.stacks
6+
kind: RuntimeComponent
7+
version: v1
8+
- group: rc.app.stacks
9+
kind: RuntimeOperation
10+
version: v1
511
- group: rc.app.stacks
612
kind: RuntimeComponent
713
version: v1beta2

api/v1/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
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 v1 contains API Schema definitions for the rc.app.stacks v1beta2 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=rc.app.stacks
20+
package v1
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: "rc.app.stacks", Version: "v1"}
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/v1/operations.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package v1
2+
3+
import (
4+
"time"
5+
6+
corev1 "k8s.io/api/core/v1"
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
)
9+
10+
// OperationStatusCondition ...
11+
// +k8s:openapi-gen=true
12+
type OperationStatusCondition struct {
13+
LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty"`
14+
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
15+
Reason string `json:"reason,omitempty"`
16+
Message string `json:"message,omitempty"`
17+
Status corev1.ConditionStatus `json:"status,omitempty"`
18+
Type OperationStatusConditionType `json:"type,omitempty"`
19+
}
20+
21+
// OperationStatusConditionType ...
22+
type OperationStatusConditionType string
23+
24+
const (
25+
// OperationStatusConditionTypeStarted indicates whether operation has been started
26+
OperationStatusConditionTypeStarted OperationStatusConditionType = "Started"
27+
// OperationStatusConditionTypeCompleted indicates whether operation has been completed
28+
OperationStatusConditionTypeCompleted OperationStatusConditionType = "Completed"
29+
)
30+
31+
// GetOperationCondition returns condition of specific type
32+
func GetOperationCondition(c []OperationStatusCondition, t OperationStatusConditionType) *OperationStatusCondition {
33+
for i := range c {
34+
if c[i].Type == t {
35+
return &c[i]
36+
}
37+
}
38+
return nil
39+
}
40+
41+
// SetOperationCondition set condition of specific type or appends if not present
42+
func SetOperationCondition(c []OperationStatusCondition, oc OperationStatusCondition) []OperationStatusCondition {
43+
condition := GetOperationCondition(c, oc.Type)
44+
45+
if condition != nil {
46+
if condition.Status != oc.Status {
47+
condition.LastTransitionTime = &metav1.Time{Time: time.Now()}
48+
}
49+
condition.Status = oc.Status
50+
condition.LastUpdateTime = metav1.Time{Time: time.Now()}
51+
condition.Reason = oc.Reason
52+
condition.Message = oc.Message
53+
return c
54+
}
55+
oc.LastUpdateTime = metav1.Time{Time: time.Now()}
56+
c = append(c, oc)
57+
return c
58+
}

api/v1/runtimecomponent_types.go

Lines changed: 1209 additions & 0 deletions
Large diffs are not rendered by default.

api/v1/runtimeoperation_types.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
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 v1
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+
// Defines the desired state of RuntimeOperation
27+
type RuntimeOperationSpec struct {
28+
// Name of the Pod to perform runtime operation on. Pod must be from the same namespace as the RuntimeOperation instance.
29+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Pod Name",xDescriptors="urn:alm:descriptor:com.tectonic.ui:text"
30+
PodName string `json:"podName"`
31+
32+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Container Name",xDescriptors="urn:alm:descriptor:com.tectonic.ui:text"
33+
ContainerName string `json:"containerName,omitempty"`
34+
35+
// Command to execute. Not executed within a shell.
36+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Command",xDescriptors="urn:alm:descriptor:com.tectonic.ui:text"
37+
Command []string `json:"command"`
38+
}
39+
40+
// Defines the observed state of RuntimeOperation.
41+
type RuntimeOperationStatus struct {
42+
// +listType=atomic
43+
Conditions []OperationStatusCondition `json:"conditions,omitempty"`
44+
}
45+
46+
// +kubebuilder:object:root=true
47+
// +kubebuilder:subresource:status
48+
// +kubebuilder:storageversion
49+
//+operator-sdk:csv:customresourcedefinitions:displayName="RuntimeOperation"
50+
51+
// Day-2 operation to execute on an instance of runtime component
52+
type RuntimeOperation struct {
53+
metav1.TypeMeta `json:",inline"`
54+
metav1.ObjectMeta `json:"metadata,omitempty"`
55+
56+
Spec RuntimeOperationSpec `json:"spec,omitempty"`
57+
Status RuntimeOperationStatus `json:"status,omitempty"`
58+
}
59+
60+
// +kubebuilder:object:root=true
61+
62+
// RuntimeOperationList contains a list of RuntimeOperation.
63+
type RuntimeOperationList struct {
64+
metav1.TypeMeta `json:",inline"`
65+
metav1.ListMeta `json:"metadata,omitempty"`
66+
Items []RuntimeOperation `json:"items"`
67+
}
68+
69+
func init() {
70+
SchemeBuilder.Register(&RuntimeOperation{}, &RuntimeOperationList{})
71+
}

0 commit comments

Comments
 (0)