Skip to content

Commit

Permalink
feat: Webhook creates Service, Service creates ServiceRun, ServiceRun…
Browse files Browse the repository at this point in the history
… creates Event (#30)

Signed-off-by: odubajDT <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Co-authored-by: Florian Bacher <[email protected]>
  • Loading branch information
odubajDT and bacherfl authored Sep 26, 2022
1 parent f6badfd commit 5ae58c3
Show file tree
Hide file tree
Showing 18 changed files with 8,528 additions and 150 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
# vendor/

.idea

.dccache*
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
namespace: {{ .Values.scheduler.namespace }}
data:
scheduler-config.yaml: |
apiVersion: kubescheduler.config.k8s.io/v1
apiVersion: kubescheduler.config.k8s.io/v1beta3
kind: KubeSchedulerConfiguration
leaderElection:
leaderElect: {{ .Values.scheduler.leaderElect }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

scheduler:
name: keptn-scheduler
image: #we still do not have a register setup, edit the Makefile to point to your own register, run 'make push-release-images' copy the resulting image here
namespace: keptn-scheduler
image: docker.io/odubajdt/kube-scheduler:202209261664175687-v0.24.3 #we still do not have a register setup, edit the Makefile to point to your own register, run 'make push-release-images' copy the resulting image here
namespace: operator-system
replicaCount: 1
leaderElect: false

Expand Down
2 changes: 1 addition & 1 deletion lfc-scheduler/manifests/permit/scheduler-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: kubescheduler.config.k8s.io/v1
apiVersion: kubescheduler.config.k8s.io/v1beta3
kind: KubeSchedulerConfiguration
leaderElection:
leaderElect: false
Expand Down
2 changes: 2 additions & 0 deletions operator/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ testbin/*
*.swp
*.swo
*~

.dccache*
6 changes: 6 additions & 0 deletions operator/api/v1alpha1/common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package common

const ServiceAnnotation = "keptn.sh/service"
const VersionAnnotation = "keptn.sh/version"
const ApplicationAnnotation = "keptn.sh/application"
const EventAnnotation = "keptn.sh/event"
30 changes: 14 additions & 16 deletions operator/api/v1alpha1/service_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,30 @@ limitations under the License.
package v1alpha1

import (
"strings"

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

type ResourceReference struct {
UID types.UID `json:"uid"`
Kind string `json:"kind"`
}

// 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 {
ApplicationName string `json:"application,omitempty"`
PreDeplymentCheck EventSpec `json:"preDeploymentCheck"`
ApplicationName string `json:"application"`
Version string `json:"version"`
PreDeploymentCheck EventSpec `json:"preDeploymentCheck"`
ResourceReference ResourceReference `json:"resourceReference"`
}

// ServiceStatus defines the observed state of Service
type ServiceStatus struct {
Phase ServiceRunPhase `json:"phase"`
ServiceRunName string `json:"serviceRunName"`
}

//+kubebuilder:object:root=true
Expand Down Expand Up @@ -60,16 +68,6 @@ func init() {
SchemeBuilder.Register(&Service{}, &ServiceList{})
}

func (s Service) IsCompleted() bool {
if s.Status.Phase == ServiceRunSucceeded || s.Status.Phase == ServiceRunFailed || s.Status.Phase == ServiceRunUnknown {
return true
}
return false
}

func (s Service) IsServiceRunNotCreated() bool {
if s.Status.Phase == "" {
return true
}
return false
func (s Service) GetServiceRunName() string {
return strings.ToLower(s.Name + "-" + s.Spec.Version)
}
14 changes: 9 additions & 5 deletions operator/api/v1alpha1/servicerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import (

// ServiceRunSpec defines the desired state of ServiceRun
type ServiceRunSpec struct {
ServiceName string `json:"serviceName,omitempty"`
PreDeploymentCheck EventSpec `json:"preDeploymentCheck"`
ApplicationName string `json:"application"`
Version string `json:"version"`
ResourceReference ResourceReference `json:"resourceReference"`
}

type ServiceRunPhase string
Expand All @@ -46,8 +49,9 @@ const (

// ServiceRunStatus defines the observed state of ServiceRun
type ServiceRunStatus struct {
Phase ServiceRunPhase `json:"phase"`
PreDeploymentCheckName string `json:"preDeploymentCheckName"`
PreDeploymentPhase ServiceRunPhase `json:"preDeploymentPhase"`
PreDeploymentTaskName string `json:"preDeploymentTaskName"`
PostDeploymentTaskName string `json:"postDeploymentTaskName"`
}

//+kubebuilder:object:root=true
Expand Down Expand Up @@ -76,14 +80,14 @@ func init() {
}

func (s ServiceRun) IsCompleted() bool {
if s.Status.Phase == ServiceRunSucceeded || s.Status.Phase == ServiceRunFailed || s.Status.Phase == ServiceRunUnknown {
if s.Status.PreDeploymentPhase == ServiceRunSucceeded || s.Status.PreDeploymentPhase == ServiceRunFailed || s.Status.PreDeploymentPhase == ServiceRunUnknown {
return true
}
return false
}

func (s ServiceRun) IsDeploymentCheckNotCreated() bool {
if s.Status.Phase == ServiceRunPending || s.Status.PreDeploymentCheckName == "" {
if s.Status.PreDeploymentPhase == ServiceRunPending || s.Status.PreDeploymentTaskName == "" {
return true
}
return false
Expand Down
46 changes: 40 additions & 6 deletions operator/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 20 additions & 8 deletions operator/config/crd/bases/lifecycle.keptn.sh_applications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9691,19 +9691,31 @@ spec:
service:
type: string
type: object
resourceReference:
properties:
kind:
type: string
uid:
description: UID is a type that holds unique ID values,
including UUIDs. Because we don't ONLY use UUIDs,
this is an alias to string. Being a type captures
intent and helps make sure that UIDs and names do
not get conflated.
type: string
required:
- kind
- uid
type: object
version:
type: string
required:
- application
- preDeploymentCheck
- resourceReference
- version
type: object
status:
description: ServiceStatus defines the observed state of Service
properties:
phase:
type: string
serviceRunName:
type: string
required:
- phase
- serviceRunName
type: object
type: object
type: array
Expand Down
Loading

0 comments on commit 5ae58c3

Please sign in to comment.