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

PoC: use PodSchedulingReadiness API to replace scheduler #632

Closed
wants to merge 15 commits into from
9 changes: 6 additions & 3 deletions .github/actions/deploy-klt-on-cluster/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ inputs:
required: false
description: "Kubernetes that should be used"
# renovate: datasource=github-releases depName=kubernetes/kubernetes
default: "v1.25.3"
default: "v1.26.0"
functions_runtime_tag:
description: "Tag for the functions runner image"
required: true
cluster-name:
required: false
description: "Name of the kind cluster"
default: "test-cluster"
cluster-config:
required: false
description: "Config of the kind cluster"
default: "test/integration/kind-cluster-config.yaml"

runs:
using: "composite"
Expand All @@ -46,6 +50,7 @@ runs:
version: ${{ inputs.kind-version }}
node_image: "kindest/node:${{ inputs.k8s-version }}"
kubectl_version: ${{ inputs.k8s-version }}
config: ${{ inputs.cluster-config }}

- name: Import images in k3d
shell: bash
Expand All @@ -71,6 +76,4 @@ runs:
sed -i 's/imagePullPolicy: Always/imagePullPolicy: Never/g' ~/download/artifacts/keptn-lifecycle-operator-manifest-test/release.yaml
sed -i 's/ghcr.keptn.sh\/keptn\/functions-runtime:.*/localhost:5000\/keptn\/functions-runtime:${{ inputs.functions_runtime_tag }}/g' ~/download/artifacts/keptn-lifecycle-operator-manifest-test/release.yaml
kubectl apply -f ~/download/artifacts/keptn-lifecycle-operator-manifest-test
kubectl apply -f ~/download/artifacts/scheduler-manifest-test
kubectl rollout status deployment keptn-scheduler -n keptn-lifecycle-toolkit-system -w
kubectl rollout status deployment klc-controller-manager -n keptn-lifecycle-toolkit-system -w
9 changes: 0 additions & 9 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ env:
# renovate: datasource=github-releases depName=kubernetes-sigs/controller-tools
CONTROLLER_TOOLS_VERSION: "v0.9.2"
ENVTEST_K8S_VERSION: "1.24.2"
SCHEDULER_COMPATIBLE_K8S_VERSION: "v0.24.3"
defaults:
run:
shell: bash
Expand Down Expand Up @@ -66,8 +65,6 @@ jobs:
config:
- name: "keptn-lifecycle-operator"
folder: "operator/"
- name: "scheduler"
folder: "scheduler/"
- name: "keptn-cert-manager"
folder: "klt-cert-manager/"
steps:
Expand Down Expand Up @@ -105,8 +102,6 @@ jobs:
config:
- name: "keptn-lifecycle-operator"
folder: "operator/"
- name: "scheduler"
folder: "scheduler/"
- name: "functions-runtime"
folder: "functions-runtime/"
- name: "keptn-cert-manager"
Expand All @@ -132,7 +127,6 @@ jobs:
RELEASE_VERSION=dev-${{ env.DATETIME }}
BUILD_TIME=${{ env.BUILD_TIME }}
CONTROLLER_TOOLS_VERSION=${{ env.CONTROLLER_TOOLS_VERSION }}
SCHEDULER_COMPATIBLE_K8S_VERSION=${{ env.SCHEDULER_COMPATIBLE_K8S_VERSION }}
builder: ${{ steps.buildx.outputs.name }}
push: false
cache-from: type=gha,scope=${{ github.ref_name }}-${{ matrix.config.name }}
Expand Down Expand Up @@ -204,8 +198,6 @@ jobs:
config:
- name: "keptn-lifecycle-operator"
folder: "operator/"
- name: "scheduler"
folder: "scheduler/"
- name: "functions-runtime"
folder: "functions-runtime/"
- name: "keptn-cert-manager"
Expand Down Expand Up @@ -240,7 +232,6 @@ jobs:
RELEASE_VERSION=dev-${{ env.DATETIME }}
BUILD_TIME=${{ env.BUILD_TIME }}
CONTROLLER_TOOLS_VERSION=${{ env.CONTROLLER_TOOLS_VERSION }}
SCHEDULER_COMPATIBLE_K8S_VERSION=${{ env.SCHEDULER_COMPATIBLE_K8S_VERSION }}
builder: ${{ steps.buildx.outputs.name }}
push: true
cache-from: type=gha,scope=${{ github.ref_name }}-${{ matrix.config.name }}
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ jobs:
config:
- name: "keptn-lifecycle-operator"
folder: "operator/"
- name: "scheduler"
folder: "scheduler/"
steps:
- name: Check out code
uses: actions/checkout@v3
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ jobs:
config:
- name: "keptn-lifecycle-operator"
folder: "operator/"
- name: "scheduler"
folder: "scheduler/"
steps:
- name: Check out code
uses: actions/checkout@v3
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ env:
GO_VERSION: "~1.19"
# renovate: datasource=github-releases depName=kubernetes-sigs/controller-tools
CONTROLLER_TOOLS_VERSION: "v0.9.2"
SCHEDULER_COMPATIBLE_K8S_VERSION: "v0.24.3"

jobs:
release-please:
Expand Down Expand Up @@ -45,8 +44,6 @@ jobs:
config:
- name: "keptn-lifecycle-operator"
folder: "operator/"
- name: "scheduler"
folder: "scheduler/"
- name: "functions-runtime"
folder: "functions-runtime/"
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -89,7 +86,6 @@ jobs:
RELEASE_VERSION=dev-${{ env.DATETIME }}
BUILD_TIME=${{ env.BUILD_TIME }}
CONTROLLER_TOOLS_VERSION=${{ env.CONTROLLER_TOOLS_VERSION }}
SCHEDULER_COMPATIBLE_K8S_VERSION=${{ env.SCHEDULER_COMPATIBLE_K8S_VERSION }}
builder: ${{ steps.buildx.outputs.name }}
push: true
cache-from: type=gha,scope=${{ github.ref_name }}-${{ matrix.config.name }}
Expand Down Expand Up @@ -133,13 +129,11 @@ jobs:
RELEASE_REGISTRY: ghcr.keptn.sh/keptn
TAG: ${{ needs.release-please.outputs.tag_name }}
run: |
cd scheduler
make release-manifests
cd ../operator
make controller-gen release-manifests
cd ..
echo "---" >> operator/config/rendered/release.yaml
cat operator/config/rendered/release.yaml scheduler/config/rendered/release.yaml > manifest.yaml
cat operator/config/rendered/release.yaml > manifest.yaml

- name: Attach release assets
uses: softprops/action-gh-release@v1
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/security-scans.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ jobs:
name: manifests
path: |
./dist/keptn-lifecycle-operator-manifest/
./dist/scheduler-manifest/

- name: Upload images
uses: actions/upload-artifact@v3
Expand All @@ -58,7 +57,6 @@ jobs:
path: |
./dist/functions-runtime-image.tar/
./dist/keptn-lifecycle-operator-image.tar/
./dist/scheduler-image.tar/

security-scans:
name: "Security Scans"
Expand Down Expand Up @@ -124,12 +122,11 @@ jobs:
cd operator/config/default
sed -i 's/\- ..\/crd//' kustomization.yaml && kustomize build ./ > /tmp/operator-manifest.yaml
cd ../crd && kustomize build ./ > /tmp/crds.yaml
cd ../../../scheduler/manifests/install && kustomize build ./ > /tmp/scheduler-manifest.yaml

curl -s https://raw.githubusercontent.com/yannh/kubeconform/${{ matrix.version }}/scripts/openapi2jsonschema.py > /tmp/openapi2jsonschema.py
mkdir -p /tmp/schema && cd /tmp/schema
python3 ../openapi2jsonschema.py ../crds.yaml
cd .. && echo "---" >> operator-manifest.yaml && cat operator-manifest.yaml scheduler-manifest.yaml > manifest.yaml
cd .. && echo "---" >> operator-manifest.yaml && cat operator-manifest.yaml > manifest.yaml
kubeconform -schema-location default -schema-location './schema/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json' -schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/cert-manager.io/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json' -summary manifest.yaml

- name: Kubescape Scan
Expand All @@ -153,7 +150,6 @@ jobs:
image:
- "functions-runtime"
- "keptn-lifecycle-operator"
- "scheduler"
steps:
- name: Download images
id: download_images
Expand All @@ -177,7 +173,6 @@ jobs:
matrix:
artifact:
- "operator"
- "scheduler"

steps:
- name: Set up Go 1.x
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/validate-semantic-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
test
deps
scopes: |
scheduler
operator
functions-runtime
dashboards
Expand Down
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,10 @@ build-deploy-operator: deploy-cert-manager

kubectl apply -f operator/config/rendered/release.yaml

.PHONY: build-deploy-scheduler
build-deploy-scheduler:
$(MAKE) -C scheduler release-local.$(ARCH) RELEASE_REGISTRY=$(RELEASE_REGISTRY) TAG=$(TAG)
$(MAKE) -C scheduler push-local RELEASE_REGISTRY=$(RELEASE_REGISTRY) TAG=$(TAG)
$(MAKE) -C scheduler release-manifests RELEASE_REGISTRY=$(RELEASE_REGISTRY) TAG=$(TAG) ARCH=$(ARCH)
kubectl create namespace keptn-lifecycle-toolkit-system --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -f scheduler/config/rendered/release.yaml

.PHONY: deploy-cert-manager
deploy-cert-manager:
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/$(CERT_MANAGER_VERSION)/cert-manager.yaml

.PHONY: build-deploy-dev-environment
build-deploy-dev-environment: build-deploy-operator build-deploy-scheduler
build-deploy-dev-environment: build-deploy-operator
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/$(CERT_MANAGER_VERSION)/cert-manager.yaml
4 changes: 0 additions & 4 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ flags:
paths:
- operator/
carryforward: true
scheduler:
paths:
- scheduler/
carryforward: true
component-tests:
paths:
- operator/
Expand Down
10 changes: 10 additions & 0 deletions examples/observability/pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
2 changes: 1 addition & 1 deletion examples/support/observability/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ deploy-podtatohead-failed-pre:
kubectl create namespace "$(PODTATO_NAMESPACE)" --dry-run=client -o yaml | kubectl apply -f -
kubectl annotate namespace "$(PODTATO_NAMESPACE)" keptn.sh/lifecycle-toolkit=enabled --overwrite
kubectl apply -f ./assets/podtatohead-deployment-evaluation/.
kubectl apply -f ./assets/podtatohead-evaluationdefinitions/keptnevaluationdefinition3.yaml
kubectl apply -f ./assets/podtatohead-evaluationdefinitions/keptnevaluationdefinition2.yaml
kubectl apply -f ./assets/podtatohead-evaluationdefinitions/keptnevaluationdefinition4.yaml
kubectl wait --for=condition=available deployment/podtato-head-entry -n podtato-kubectl --timeout=120s
@echo "Watch Workload Deployment Progress: kubectl get keptnworkloadinstances -n podtato-kubectl -w"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ spec:
postDeploymentTasks:
- post-deployment-hello
preDeploymentEvaluations: #Comment out this four lines if you do not have a prometheus installation
- my-prometheus-definition1
- my-prometheus-definition2
postDeploymentEvaluations:
- my-prometheus-definition2
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
initContainers:
- name: init-myservice
image: busybox:1.28
command: ['sh', '-c', 'sleep 30']
command: ['sh', '-c', 'sleep 10']
containers:
- name: server
image: ghcr.io/podtato-head/entry:latest
Expand Down Expand Up @@ -77,7 +77,7 @@ spec:
component: podtato-head-hat
keptn.sh/pre-deployment-tasks: check-entry-service
keptn.sh/pre-deployment-evaluations: my-prometheus-definition1
keptn.sh/post-deployment-evaluations: my-prometheus-definition1
keptn.sh/post-deployment-evaluations: my-prometheus-definition2
annotations:
keptn.sh/app: podtato-head
keptn.sh/workload: podtato-head-hat
Expand Down
1 change: 1 addition & 0 deletions operator/apis/lifecycle/v1alpha2/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const K8sRecommendedVersionAnnotations = "app.kubernetes.io/version"
const K8sRecommendedAppAnnotations = "app.kubernetes.io/part-of"
const PreDeploymentEvaluationAnnotation = "keptn.sh/pre-deployment-evaluations"
const PostDeploymentEvaluationAnnotation = "keptn.sh/post-deployment-evaluations"
const SchedullingGateRemoved = "keptn.sh/schedulling-gate-removed"
const TaskNameAnnotation = "keptn.sh/task-name"
const NamespaceEnabledAnnotation = "keptn.sh/lifecycle-toolkit"
const CreateAppTaskSpanName = "create_%s_app_task"
Expand Down
1 change: 1 addition & 0 deletions operator/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ rules:
verbs:
- get
- list
- update
- watch
- apiGroups:
- ""
Expand Down
67 changes: 67 additions & 0 deletions operator/controllers/common/helperfunctions.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package common

import (
"context"

"github.com/go-logr/logr"
klcv1alpha2 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha2"
apicommon "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha2/common"
controllererrors "github.com/keptn/lifecycle-toolkit/operator/controllers/errors"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type CreateAttributes struct {
Expand Down Expand Up @@ -41,3 +47,64 @@ func GetOldStatus(name string, statuses []klcv1alpha2.ItemStatus) apicommon.Kept

return oldstatus
}

func RemoveGates(ctx context.Context, c client.Client, log logr.Logger, workloadInstance *klcv1alpha2.KeptnWorkloadInstance) error {
switch workloadInstance.Spec.ResourceReference.Kind {
case "Pod":
return removePodGates(ctx, c, log, workloadInstance.Spec.ResourceReference.Name, workloadInstance.Namespace)
case "ReplicaSet", "StatefulSet", "DaemonSet":
podList, err := getPodsOfOwner(ctx, c, log, workloadInstance.Spec.ResourceReference.UID, workloadInstance.Spec.ResourceReference.Kind, workloadInstance.Namespace)
if err != nil {
log.Error(err, "cannot get pods")
return err
}
for _, pod := range podList {
err := removePodGates(ctx, c, log, pod, workloadInstance.Namespace)
if err != nil {
log.Error(err, "cannot remove gates from pod")
return err
}
}
default:
return controllererrors.ErrUnsupportedWorkloadInstanceResourceReference
}

return nil
}

func removePodGates(ctx context.Context, c client.Client, log logr.Logger, podName string, podNamespace string) error {
pod := &v1.Pod{}
err := c.Get(ctx, types.NamespacedName{Namespace: podNamespace, Name: podName}, pod)
if err != nil {
log.Error(err, "cannot remove gates from pod - inner")
return err
}
if len(pod.Annotations) == 0 {
pod.Annotations = make(map[string]string)
}
pod.Annotations[apicommon.SchedullingGateRemoved] = "true"
pod.Spec.SchedulingGates = nil
return c.Update(ctx, pod)
}

func getPodsOfOwner(ctx context.Context, c client.Client, log logr.Logger, ownerUID types.UID, ownerKind string, namespace string) ([]string, error) {
pods := &v1.PodList{}
err := c.List(ctx, pods, client.InNamespace(namespace))
if err != nil {
log.Error(err, "cannot list pods - inner")
return nil, err
}

var resultPods []string

for _, pod := range pods.Items {
for _, owner := range pod.OwnerReferences {
if owner.Kind == ownerKind && owner.UID == ownerUID {
resultPods = append(resultPods, pod.Name)
break
}
}
}

return resultPods, nil
}
Loading