Skip to content

Commit

Permalink
Create V1 API (#461)
Browse files Browse the repository at this point in the history
* Create V1 API

* Update tests to v1

* Update project file

* Add v1 sample to CSV

* use kubectl create
  • Loading branch information
arturdzm authored Mar 7, 2023
1 parent 6f09d18 commit 085f869
Show file tree
Hide file tree
Showing 188 changed files with 21,346 additions and 721 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Current Operator version.
VERSION ?= 0.8.1
VERSION ?= 1.0.0
OPERATOR_SDK_RELEASE_VERSION ?= v1.24.0

# CHANNELS define the bundle channels used in the bundle.
Expand Down
6 changes: 6 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ layout: go.kubebuilder.io/v3
projectName: runtime-component
repo: github.com/application-stacks/runtime-component-operator
resources:
- group: rc.app.stacks
kind: RuntimeComponent
version: v1
- group: rc.app.stacks
kind: RuntimeOperation
version: v1
- group: rc.app.stacks
kind: RuntimeComponent
version: v1beta2
Expand Down
36 changes: 36 additions & 0 deletions api/v1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1 contains API Schema definitions for the rc.app.stacks v1beta2 API group
// +kubebuilder:object:generate=true
// +groupName=rc.app.stacks
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "rc.app.stacks", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
58 changes: 58 additions & 0 deletions api/v1/operations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package v1

import (
"time"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// OperationStatusCondition ...
// +k8s:openapi-gen=true
type OperationStatusCondition struct {
LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty"`
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"`
Status corev1.ConditionStatus `json:"status,omitempty"`
Type OperationStatusConditionType `json:"type,omitempty"`
}

// OperationStatusConditionType ...
type OperationStatusConditionType string

const (
// OperationStatusConditionTypeStarted indicates whether operation has been started
OperationStatusConditionTypeStarted OperationStatusConditionType = "Started"
// OperationStatusConditionTypeCompleted indicates whether operation has been completed
OperationStatusConditionTypeCompleted OperationStatusConditionType = "Completed"
)

// GetOperationCondition returns condition of specific type
func GetOperationCondition(c []OperationStatusCondition, t OperationStatusConditionType) *OperationStatusCondition {
for i := range c {
if c[i].Type == t {
return &c[i]
}
}
return nil
}

// SetOperationCondition set condition of specific type or appends if not present
func SetOperationCondition(c []OperationStatusCondition, oc OperationStatusCondition) []OperationStatusCondition {
condition := GetOperationCondition(c, oc.Type)

if condition != nil {
if condition.Status != oc.Status {
condition.LastTransitionTime = &metav1.Time{Time: time.Now()}
}
condition.Status = oc.Status
condition.LastUpdateTime = metav1.Time{Time: time.Now()}
condition.Reason = oc.Reason
condition.Message = oc.Message
return c
}
oc.LastUpdateTime = metav1.Time{Time: time.Now()}
c = append(c, oc)
return c
}
1,209 changes: 1,209 additions & 0 deletions api/v1/runtimecomponent_types.go

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions api/v1/runtimeoperation_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// Defines the desired state of RuntimeOperation
type RuntimeOperationSpec struct {
// Name of the Pod to perform runtime operation on. Pod must be from the same namespace as the RuntimeOperation instance.
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Pod Name",xDescriptors="urn:alm:descriptor:com.tectonic.ui:text"
PodName string `json:"podName"`

// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Container Name",xDescriptors="urn:alm:descriptor:com.tectonic.ui:text"
ContainerName string `json:"containerName,omitempty"`

// Command to execute. Not executed within a shell.
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Command",xDescriptors="urn:alm:descriptor:com.tectonic.ui:text"
Command []string `json:"command"`
}

// Defines the observed state of RuntimeOperation.
type RuntimeOperationStatus struct {
// +listType=atomic
Conditions []OperationStatusCondition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
//+operator-sdk:csv:customresourcedefinitions:displayName="RuntimeOperation"

// Day-2 operation to execute on an instance of runtime component
type RuntimeOperation struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec RuntimeOperationSpec `json:"spec,omitempty"`
Status RuntimeOperationStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// RuntimeOperationList contains a list of RuntimeOperation.
type RuntimeOperationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []RuntimeOperation `json:"items"`
}

func init() {
SchemeBuilder.Register(&RuntimeOperation{}, &RuntimeOperationList{})
}
Loading

0 comments on commit 085f869

Please sign in to comment.