Skip to content

Commit

Permalink
feat: substitute event task (#43)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Schuetz <[email protected]>
Signed-off-by: odubajDT <[email protected]>
Signed-off-by: RealAnna <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Co-authored-by: Thomas Schuetz <[email protected]>
Co-authored-by: RealAnna <[email protected]>
Co-authored-by: Florian Bacher <[email protected]>
  • Loading branch information
4 people authored Sep 29, 2022
1 parent d7ba5f3 commit 3644a7d
Show file tree
Hide file tree
Showing 37 changed files with 913 additions and 44,266 deletions.
11 changes: 1 addition & 10 deletions lfc-scheduler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ build-scheduler:
.PHONY: build-scheduler.amd64
build-scheduler.amd64:
$(COMMONENVVAR) $(BUILDENVVAR) GOARCH=amd64 go build -ldflags '-X k8s.io/component-base/version.gitVersion=$(VERSION) -w' -o bin/kube-scheduler cmd/scheduler/main.go
#go build -ldflags '-X k8s.io/component-base/version.gitVersion=$(VERSION) -w' -o bin/kube-scheduler cmd/scheduler/main.go

.PHONY: build-scheduler.arm64v8
build-scheduler.arm64v8:
Expand Down Expand Up @@ -110,7 +109,6 @@ release-manifests: kustomize
.PHONY: local-image
local-image: clean
docker build --build-arg ARCH="amd64" --build-arg RELEASE_VERSION="$(RELEASE_VERSION)" -t $(LOCAL_REGISTRY)/$(LOCAL_IMAGE) .
#docker build -f ./build/controller/Dockerfile --build-arg ARCH="amd64" -t $(LOCAL_REGISTRY)/$(LOCAL_CONTROLLER_IMAGE) .

.PHONY: build-and-push-image
build-and-push-image: release-image push-release-images
Expand All @@ -121,28 +119,21 @@ release-image: release-image.amd64 release-image.arm64v8
.PHONY: release-image.amd64
release-image.amd64: clean
docker build --load --build-arg ARCH="amd64" --build-arg RELEASE_VERSION="$(RELEASE_VERSION)" -t $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-amd64 .
#docker build -f ./build/controller/Dockerfile --build-arg ARCH="amd64" -t $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE)-amd64 .

.PHONY: release-image.arm64v8
release-image.arm64v8: clean
docker build --load --build-arg ARCH="arm64v8" --build-arg RELEASE_VERSION="$(RELEASE_VERSION)" -t $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-arm64 .
#docker build -f ./build/controller/Dockerfile --build-arg ARCH="arm64v8" -t $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE)-arm64 .
docker build --load --build-arg ARCH="arm64v8" --build-arg RELEASE_VERSION="$(RELEASE_VERSION)" -t $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-arm64 .

.PHONY: push-release-images
push-release-images: release-image.amd64 release-image.arm64v8
#gcloud auth configure-docker
for arch in $(ARCHS); do \
docker push $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-$${arch} ;\
#docker push $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE)-$${arch} ;\
done
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create $(RELEASE_REGISTRY)/$(RELEASE_IMAGE) $(addprefix --amend $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-, $(ARCHS))
#DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE) $(addprefix --amend $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE)-, $(ARCHS))
for arch in $(ARCHS); do \
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest annotate --arch $${arch} $(RELEASE_REGISTRY)/$(RELEASE_IMAGE) $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-$${arch} ;\
#DOCKER_CLI_EXPERIMENTAL=enabled docker manifest annotate --arch $${arch} $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE) $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE)-$${arch} ;\
done
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push $(RELEASE_REGISTRY)/$(RELEASE_IMAGE) ;\
#DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE) ;\

.PHONY: clean
clean:
Expand Down
37 changes: 37 additions & 0 deletions lfc-scheduler/manifests/install/charts/keptn-scheduler/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

# Default values for scheduler-plugins-as-a-second-scheduler.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

scheduler:
name: keptn-scheduler
image: docker.io/annadreal/kube-scheduler:202209271664295209-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: keptn-lifecycle-controller-system
replicaCount: 1
leaderElect: false

#controller:
# name: scheduler-plugins-controller
# image: k8s.gcr.io/scheduler-plugins/controller:v0.23.10
# namespace: keptn-scheduler
# replicaCount: 1

# LoadVariationRiskBalancing and TargetLoadPacking are not enabled by default
# as they need extra RBAC privileges on metrics.k8s.io.

plugins:
enabled: ["KLCPermit"]
disabled: [] # only in-tree plugins need to be defined here

# Customize the enabled plugins' config.
# Refer to the "pluginConfig" section of manifests/<plugin>/scheduler-config.yaml.
# For example, for Coscheduling plugin, you want to customize the permit waiting timeout to 10 seconds:
#pluginConfig:
#- name: Coscheduling
# args:
# permitWaitingTimeSeconds: 10 # default is 60
# Or, customize the other plugins
# - name: NodeResourceTopologyMatch
# args:
# scoringStrategy:
# type: MostAllocated # default is LeastAllocated
5 changes: 3 additions & 2 deletions lfc-scheduler/pkg/klcpermit/permit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package klcpermit

import (
"context"
"time"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/scheduler/framework"
"time"
)

// Name is the name of the plugin used in the plugin registry and configurations.
Expand Down Expand Up @@ -46,7 +47,7 @@ func (pl *Permit) Permit(ctx context.Context, state *framework.CycleState, p *v1
return framework.NewStatus(framework.Success), 0 * time.Second
default:
klog.Infof("[Keptn Permit Plugin] unknown status of pre-deployment checks for", p.GetObjectMeta().GetName())
return framework.NewStatus(framework.Wait), 30 * time.Second //TODO what makes sense here?
return framework.NewStatus(framework.Wait), 30 * time.Second
}

}
Expand Down
34 changes: 14 additions & 20 deletions lfc-scheduler/pkg/klcpermit/workflow_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,14 @@ const (
Wait Status = "Wait"
)

type WorkloadInstancePhase string
type KeptnState string

const (
// WorkloadInstancePending means the application has been accepted by the system, but one or more of its
// workloadInstances has not been started.
WorkloadInstancePending WorkloadInstancePhase = "Pending"
// WorkloadInstanceRunning means that workloadInstance has been started.
WorkloadInstanceRunning WorkloadInstancePhase = "Running"
// WorkloadInstanceSucceeded means that workloadInstance has been finished successfully.
WorkloadInstanceSucceeded WorkloadInstancePhase = "Succeeded"
// WorkloadInstanceFailed means that one or more pre-deployment checks was not successful and terminated.
WorkloadInstanceFailed WorkloadInstancePhase = "Failed"
// WorkloadInstanceUnknown means that for some reason the state of the application could not be obtained.
WorkloadInstanceUnknown WorkloadInstancePhase = "Unknown"
StateRunning KeptnState = "Running"
StateSucceeded KeptnState = "Succeeded"
StateFailed KeptnState = "Failed"
StateUnknown KeptnState = "Unknown"
StatePending KeptnState = "Pending"
)

type Manager interface {
Expand All @@ -57,26 +51,26 @@ func NewWorkloadManager(d dynamic.Interface) *WorkloadManager {
func (sMgr *WorkloadManager) Permit(ctx context.Context, pod *corev1.Pod) Status {
//List workloadInstance run CRDs
name := GetCRDName(pod)
crd, err := sMgr.GetCRD(ctx, metav1.NamespaceDefault, name)
crd, err := sMgr.GetCRD(ctx, pod.Namespace, name)

if err != nil {
klog.Infof("[Keptn Permit Plugin] could not find workloadInstance crd %s, err:%s", name, err.Error())
return WorkloadInstanceNotFound
}
//check CRD status
phase, found, err := unstructured.NestedString(crd.UnstructuredContent(), "status", "phase")
phase, found, err := unstructured.NestedString(crd.UnstructuredContent(), "status", "preDeploymentStatus")
klog.Infof("[Keptn Permit Plugin] workloadInstance crd %s, found %s with phase %s ", crd, found, phase)
if err == nil && found {
switch WorkloadInstancePhase(phase) {
case WorkloadInstancePending:
switch KeptnState(phase) {
case StatePending:
return Wait
case WorkloadInstanceFailed:
case StateFailed:
return Failure
case WorkloadInstanceSucceeded:
case StateSucceeded:
return Success
case WorkloadInstanceRunning:
case StateRunning:
return Wait
case WorkloadInstanceUnknown:
case StateUnknown:
return Wait
}

Expand Down
40 changes: 39 additions & 1 deletion operator/api/v1alpha1/common/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
package common

import "fmt"

const WorkloadAnnotation = "keptn.sh/workload"
const VersionAnnotation = "keptn.sh/version"
const AppAnnotation = "keptn.sh/app"
const EventAnnotation = "keptn.sh/event"
const PreDeploymentTaskAnnotation = "keptn.sh/pre-deployment-tasks"
const PostDeploymentTaskAnnotation = "keptn.sh/post-deployment-tasks"
const PreDeploymentAnalysisAnnotation = "keptn.sh/pre-deployment-analysis"
const PostDeploymentAnalysisAnnotation = "keptn.sh/post-deployment-analysis"

const MaxAppNameLength = 25
const MaxWorkloadNameLength = 25
const MaxTaskNameLength = 25
const MaxVersionLength = 12

type KeptnState string

const (
StateRunning KeptnState = "Running"
StateSucceeded KeptnState = "Succeeded"
StateFailed KeptnState = "Failed"
StateUnknown KeptnState = "Unknown"
StatePending KeptnState = "Pending"
)

var ErrTooLongAnnotations = fmt.Errorf("too long annotations, maximum length for app and workload is 25 characters, for version 12 characters")

func (k KeptnState) IsCompleted() bool {
return k == StateSucceeded || k == StateFailed || k == StateUnknown
}

func TruncateString(s string, max int) string {
if len(s) > max {
return s[:max]
}
return s
}

type CheckType string

const PreDeploymentCheckType CheckType = "pre"
const PostDeploymentCheckType CheckType = "post"
25 changes: 5 additions & 20 deletions operator/api/v1alpha1/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1/common"
batchv1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -33,26 +34,10 @@ type EventSpec struct {

// EventStatus defines the observed state of Event
type EventStatus struct {
Phase EventPhase `json:"phase"`
JobName string `json:"jobName"`
Phase common.KeptnState `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

Expand All @@ -79,14 +64,14 @@ func init() {
}

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

func (e Event) IsJobNotCreated() bool {
if e.Status.Phase == EventPending || e.Status.JobName == "" {
if e.Status.Phase == common.StatePending || e.Status.JobName == "" {
return true
}
return false
Expand Down
17 changes: 2 additions & 15 deletions operator/api/v1alpha1/keptnapp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1/common"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -32,23 +33,9 @@ type KeptnAppSpec struct {

// KeptnAppStatus defines the observed state of KeptnApp
type KeptnAppStatus struct {
Status ApplicationPhase `json:"status"`
Status common.KeptnState `json:"status"`
}

type ApplicationPhase string

const (
// ApplicationPending means the application has been accepted by the system, but one or more of its
// workloads has not been started.
ApplicationPending ApplicationPhase = "Pending"
// ApplicationRunning means that all of the workloads 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
19 changes: 4 additions & 15 deletions operator/api/v1alpha1/keptntask_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1/common"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -31,21 +32,9 @@ type KeptnTaskSpec struct {
TaskDefinition string `json:"taskDefinition"`
Parameters TaskParameters `json:"parameters,omitempty"`
SecureParameters SecureParameters `json:"secureParameters,omitempty"`
Type common.CheckType `json:"checkType,omitempty"`
}

type KeptnTaskPhase string

const (
// TaskPending means the task has been accepted by the system, but the corresponding Job did not start
TaskPending KeptnTaskPhase = "Pending"
// TaskRunning means that the Job has been started.
TaskRunning KeptnTaskPhase = "Running"
// TaskFailed means that the Job failed
TaskFailed KeptnTaskPhase = "Failed"
// TaskSucceeded means that the Job has finished successfully
TaskSucceeded KeptnTaskPhase = "Succeeded"
)

type TaskParameters struct {
Inline map[string]string `json:"map,omitempty"`
}
Expand All @@ -56,8 +45,8 @@ type SecureParameters struct {

// KeptnTaskStatus defines the observed state of KeptnTask
type KeptnTaskStatus struct {
JobName string `json:"jobName,omitempty"`
Status KeptnTaskPhase `json:"status,omitempty"`
JobName string `json:"jobName,omitempty"`
Status common.KeptnState `json:"status,omitempty"`
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}
Expand Down
12 changes: 6 additions & 6 deletions operator/api/v1alpha1/keptntaskdefinition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ type KeptnTaskDefinitionSpec struct {
}

type FunctionSpec struct {
FunctionReference *FunctionReference `json:"functionRef,omitempty"`
Inline *Inline `json:"inline,omitempty"`
HttpReference *HttpReference `json:"httpRef,omitempty"`
ConfigMapReference *ConfigMapReference `json:"configMapRef,omitempty"`
Parameters TaskParameters `json:"parameters,omitempty"`
SecureParameters SecureParameters `json:"secureParameters,omitempty"`
FunctionReference FunctionReference `json:"functionRef,omitempty"`
Inline Inline `json:"inline,omitempty"`
HttpReference HttpReference `json:"httpRef,omitempty"`
ConfigMapReference ConfigMapReference `json:"configMapRef,omitempty"`
Parameters TaskParameters `json:"parameters,omitempty"`
SecureParameters SecureParameters `json:"secureParameters,omitempty"`
}

type ConfigMapReference struct {
Expand Down
13 changes: 7 additions & 6 deletions operator/api/v1alpha1/keptnworkload_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import (

// KeptnWorkloadSpec defines the desired state of KeptnWorkload
type KeptnWorkloadSpec struct {
AppName string `json:"app"`
Version string `json:"version"`
//TODO: Replace them with KeptnTasks
PreDeploymentTask *EventSpec `json:"preDeploymentTask,omitempty"`
PostDeploymentTask *EventSpec `json:"postDeploymentTask,omitempty"`
ResourceReference ResourceReference `json:"resourceReference"`
AppName string `json:"app"`
Version string `json:"version"`
PreDeploymentTasks []string `json:"preDeploymentTasks,omitempty"`
PostDeploymentTasks []string `json:"postDeploymentTasks,omitempty"`
PreDeploymentAnalysis []string `json:"preDeploymentAnalysis,omitempty"`
PostDeploymentAnalysis []string `json:"postDeploymentAnalysis,omitempty"`
ResourceReference ResourceReference `json:"resourceReference"`
}

// KeptnWorkloadStatus defines the observed state of KeptnWorkload
Expand Down
Loading

0 comments on commit 3644a7d

Please sign in to comment.