diff --git a/initializer/Dockerfile b/initializer/Dockerfile deleted file mode 100644 index 2720475c1..000000000 --- a/initializer/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM alpine:3.13.5 - -WORKDIR / -COPY qos-checking.sh / \ No newline at end of file diff --git a/initializer/podinfo b/initializer/podinfo deleted file mode 100644 index 1444295cd..000000000 --- a/initializer/podinfo +++ /dev/null @@ -1,4 +0,0 @@ -cluster="test-cluster1" -rack="rack-22" -zone="us-est-coast" -gocrane.io/cpu-qos="123" diff --git a/initializer/qos-checking.sh b/initializer/qos-checking.sh deleted file mode 100644 index 2ae9d28aa..000000000 --- a/initializer/qos-checking.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash - -ready=0 -while [ $ready -eq 0 ]; do - while read line; - do - echo $line; - if [[ $line =~ "gocrane.io/cpu-qos" ]] - then - echo "into if" - ready=1 - break - fi - done < ./podinfo - - if [[ $ready -eq 0 ]] - then - sleep 5 - fi -done - -echo "QOS Initialized" \ No newline at end of file diff --git a/pkg/webhooks/pod/mutating.go b/pkg/webhooks/pod/mutating.go index 16eec8c45..9ed650f18 100644 --- a/pkg/webhooks/pod/mutating.go +++ b/pkg/webhooks/pod/mutating.go @@ -13,6 +13,10 @@ import ( "github.com/gocrane/crane/pkg/ensurance/config" ) +var ( + SystemNamespaces = map[string]interface{}{"kube-system": nil, "crane-system": nil} +) + type MutatingAdmission struct { Config *config.QOSConfig } @@ -23,8 +27,13 @@ func (m *MutatingAdmission) Default(ctx context.Context, obj runtime.Object) err if !ok { return fmt.Errorf("expected a Pod but got a %T", obj) } + klog.Infof("Into Pod injection %s/%s", pod.Namespace, pod.Name) + if _, exist := SystemNamespaces[pod.Namespace]; exist { + return nil + } + if m.Config == nil || !m.Config.QOSInitializer.Enable { return nil } diff --git a/pkg/webhooks/pod/mutating_test.go b/pkg/webhooks/pod/mutating_test.go index 17c478334..6ab632392 100644 --- a/pkg/webhooks/pod/mutating_test.go +++ b/pkg/webhooks/pod/mutating_test.go @@ -27,7 +27,8 @@ func TestDefaultingPodQOSInitializer(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "pod1", Labels: map[string]string{ - "app": "nginx", + "app": "nginx", + "type": "offline", }, }, } diff --git a/tools/initializer/resource.yaml b/tools/initializer/resource.yaml index 371d1483d..9a5b07017 100644 --- a/tools/initializer/resource.yaml +++ b/tools/initializer/resource.yaml @@ -21,7 +21,7 @@ spec: operator: Exists containers: - name: craned - image: docker.io/gocrane/craned:v0.9.0-67-g392a9999 + image: docker.io/gocrane/craned:v0.9.0-98-gbc4b90fe imagePullPolicy: IfNotPresent env: - name: TZ @@ -32,10 +32,11 @@ spec: fieldPath: metadata.namespace command: - /craned - - --prometheus-address=http://prometheus-server.crane-system.svc.cluster.local:8080 + - --prometheus-address=http://kvass-thanos.kube-system:9090 - --feature-gates=Analysis=true,TimeSeriesPrediction=true,Autoscaling=true,QOSInitializer=true - --recommendation-configuration-file=/tmp/recommendation-config/config.yaml - --qos-config-file=/tmp/recommendation-config/qos.yaml + - --leader-elect=false - -v=4 volumeMounts: - mountPath: /tmp/k8s-webhook-server/serving-certs @@ -104,7 +105,7 @@ data: app: nginx initContainerTemplate: name: crane-qos-initializer - image: docker.io/gocrane/qos-init:v0.1.4 + image: docker.io/gocrane/qos-init:v0.1.6 imagePullPolicy: IfNotPresent command: - sh