Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of Event Controller #20

Merged
merged 7 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions operator/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,22 @@ resources:
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: keptn.sh
group: lifecycle
kind: Service
path: github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: keptn.sh
group: lifecycle
kind: Event
path: github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1
version: v1alpha1
version: "3"
25 changes: 18 additions & 7 deletions operator/api/v1alpha1/application_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,30 @@ import (

// ApplicationSpec defines the desired state of Application
type ApplicationSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of Application. Edit application_types.go to remove/update
Foo string `json:"foo,omitempty"`
Services []Service `json:"services,omitempty"`
PreDeployment []string `json:"pre-deployment,omitempty"`
PostDeployment []string `json:"post-deployment,omitempty"`
}

// ApplicationStatus defines the observed state of Application
type ApplicationStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Status ApplicationPhase `json:"status"`
}

type ApplicationPhase string

const (
// ApplicationPending means the application has been accepted by the system, but one or more of its
// services has not been started.
ApplicationPending ApplicationPhase = "Pending"
// ApplicationRunning means that all of the services have been started.
ApplicationRunning ApplicationPhase = "Running"
// ApplicationFailed means that one or more pre-deployment checks was not successful and terminated.
ApplicationFailed ApplicationPhase = "Failed"
// ApplicationUnknown means that for some reason the state of the application could not be obtained.
ApplicationUnknown ApplicationPhase = "Unknown"
)

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

Expand Down
93 changes: 93 additions & 0 deletions operator/api/v1alpha1/event_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
Copyright 2022.

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 v1alpha1

import (
batchv1 "k8s.io/api/batch/v1"
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.

// EventSpec defines the desired state of Event
type EventSpec struct {
Service string `json:"service,omitempty"`
Application string `json:"application,omitempty"`
JobSpec batchv1.JobSpec `json:"job,omitempty"`
}

// EventStatus defines the observed state of Event
type EventStatus struct {
Phase EventPhase `json:"phase"`
JobName string `json:"jobName"`
}

type EventPhase string

const (
// EventPending means the application has been accepted by the system, but one or more of its
// services has not been started.
EventPending EventPhase = "Pending"
// EventRunning means that all of the services have been started.
EventRunning EventPhase = "Running"
// EventRunning means that all of the services have been finished successfully.
EventSucceeded EventPhase = "Succeeded"
// EventFailed means that one or more pre-deployment checks was not successful and terminated.
EventFailed EventPhase = "Failed"
// EventUnknown means that for some reason the state of the application could not be obtained.
EventUnknown EventPhase = "Unknown"
)

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Event is the Schema for the events API
type Event struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec EventSpec `json:"spec,omitempty"`
Status EventStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&Event{}, &EventList{})
}

func (e Event) IsCompleted() bool {
if e.Status.Phase == EventSucceeded || e.Status.Phase == EventFailed || e.Status.Phase == EventUnknown {
return true
}
return false
}

func (e Event) IsJobNotCreated() bool {
if e.Status.Phase == EventPending || e.Status.JobName == "" {
return true
}
return false
}
64 changes: 64 additions & 0 deletions operator/api/v1alpha1/service_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright 2022.

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 v1alpha1

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.

// ServiceSpec defines the desired state of Service
type ServiceSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of Service. Edit service_types.go to remove/update
Foo string `json:"foo,omitempty"`
}

// ServiceStatus defines the observed state of Service
type ServiceStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Service is the Schema for the services API
type Service struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ServiceSpec `json:"spec,omitempty"`
Status ServiceStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&Service{}, &ServiceList{})
}
Loading