From 49e54454b13155de0b0f7fb6288bc76b76bd6fe2 Mon Sep 17 00:00:00 2001 From: nkwangleiGIT Date: Mon, 17 Oct 2022 16:32:06 +0800 Subject: [PATCH 1/5] Refine code structure and fix build --- Makefile | 28 ------------------- README.md | 12 ++++++-- .../resource-tagger/Dockerfile | 14 ++++------ executor-plugins/resource-tagger/Makefile | 12 +++----- .../resource-tagger/build-resource-tagger.sh | 1 - .../metric-server/Dockerfile | 2 +- observer-plugins/metric-server/Makefile | 12 ++++---- .../prometheus/Dockerfile | 2 +- observer-plugins/prometheus/Makefile | 10 +++---- scripts/build.sh | 2 +- scripts/clean.sh | 10 +++---- 11 files changed, 37 insertions(+), 68 deletions(-) delete mode 100644 Makefile rename build/dockerfile.resource-tagger => executor-plugins/resource-tagger/Dockerfile (57%) rename build/dockerfile.metric-server => observer-plugins/metric-server/Dockerfile (89%) rename build/dockerfile.prometheus => observer-plugins/prometheus/Dockerfile (92%) diff --git a/Makefile b/Makefile deleted file mode 100644 index 1e65d4d..0000000 --- a/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -.PHONY: build-all clean - -CGO ?=0 -GOOS ?= linux - -# now only support amd64 -ARCH ?= $(shell go env GOARCH) -#GOFLAGS ?="" -RELEASE ?=v0.1.0 - -echo: - ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/..; - echo $(ROOT) - -clean: - @./scripts/clean.sh $(RELEASE) - -build-all: clean - ./scripts/build.sh $(CGO) amd64 $(GOOS) - - -copyright: - ./scripts/verify-copyright.sh - -build-image: - docker build --build-arg CGO=${CGO} --build-arg ARCH=${ARCH} --build-arg GOOS=${GOOS} -t kubearbiter/observer-metric-server:$(RELEASE) -f build/dockerfile.metric-server . - docker build --build-arg CGO=${CGO} --build-arg ARCH=${ARCH} --build-arg GOOS=${GOOS} -t kubearbiter/observer-prometheus-server:$(RELEASE) -f build/dockerfile.prometheus . - docker build --build-arg CGO=${CGO} --build-arg ARCH=${ARCH} --build-arg GOOS=${GOOS} -t kubearbiter/executor-resource-tagger:$(RELEASE) -f build/dockerfile.resource-tagger . diff --git a/README.md b/README.md index 241eecb..da94f8b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,13 @@ # arbiter-plugins -arbiter plugin samples +Arbiter plugins to support more real scenarios. -## Description -This code repository contains examples of relevant implementations of rcp. +1. observer-plugins +metric-server: Use metric-server as the source of metrics + +prometheus: Use promethes as the source of metrics + +2. executor-plugins + +resource-tagger: Tag the resource based on the value from OBI diff --git a/build/dockerfile.resource-tagger b/executor-plugins/resource-tagger/Dockerfile similarity index 57% rename from build/dockerfile.resource-tagger rename to executor-plugins/resource-tagger/Dockerfile index 010f82c..5380f3d 100644 --- a/build/dockerfile.resource-tagger +++ b/executor-plugins/resource-tagger/Dockerfile @@ -8,15 +8,14 @@ ARG GOOS=linux WORKDIR /workspace # Copy the Go Modules manifests -COPY ../resource-tagger-plugin/go.mod go.mod -COPY ../resource-tagger-plugin/go.sum go.sum -COPY ../resource-tagger-plugin/build-resource-tagger.sh build-resource-tagger.sh +COPY go.mod go.mod +COPY go.sum go.sum +COPY build-resource-tagger.sh build-resource-tagger.sh ## Copy the go source and vendor -COPY ../resource-tagger-plugin/cmd/server/server.go cmd/server/server.go -COPY ../resource-tagger-plugin/cmd/client/client.go cmd/client/client.go -COPY ../resource-tagger-plugin/internal/ internal/ -COPY ../resource-tagger-plugin/staging staging/ +COPY cmd/server/server.go cmd/server/server.go +COPY internal/ internal/ +COPY staging staging/ RUN ./build-resource-tagger.sh ${CGO} ${ARCH} ${GOOS} @@ -28,6 +27,5 @@ RUN ./build-resource-tagger.sh ${CGO} ${ARCH} ${GOOS} FROM alpine:3.15 WORKDIR / COPY --from=builder /workspace/resource-tagger /usr/local/bin/resource-tagger -COPY --from=builder /workspace/resource-tagger-client /usr/local/bin/resource-tagger-client CMD ["resource-tagger"] diff --git a/executor-plugins/resource-tagger/Makefile b/executor-plugins/resource-tagger/Makefile index 2be27f4..dfc7563 100644 --- a/executor-plugins/resource-tagger/Makefile +++ b/executor-plugins/resource-tagger/Makefile @@ -1,6 +1,6 @@ # Global environment variables -IMAGE_REPO_ADDR = 172.22.50.227 -VERSION = v0.0.1 +IMAGE_REPO_ADDR = docker.io +VERSION = v0.1.0 ##@ General @@ -62,19 +62,15 @@ _gen-proto-doc: run: ## Run server and client locally. go run cmd/server/server.go & sleep 3 - go run cmd/client/client.go - sleep 1 - pkill server true ##@ Build build: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o resource-tagger cmd/server/server.go - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o resource-tagger-client cmd/client/client.go -buildimg: build ## Build resource-tagger plugin image. - docker build -t $(IMAGE_REPO_ADDR)/arbiter/resource-tagger-plugin:$(VERSION) . +build-image: ## Build resource-tagger plugin image. + docker build -t $(IMAGE_REPO_ADDR)/kubearbiter/executor-resource-tagger:$(VERSION) . updateimg: ## Update resource-tagger plugin image. kubectl get pod -n arbiter | grep executor | awk '{print $$1}' | xargs kubectl delete pod -n arbiter diff --git a/executor-plugins/resource-tagger/build-resource-tagger.sh b/executor-plugins/resource-tagger/build-resource-tagger.sh index 8a91986..8791b12 100755 --- a/executor-plugins/resource-tagger/build-resource-tagger.sh +++ b/executor-plugins/resource-tagger/build-resource-tagger.sh @@ -5,4 +5,3 @@ ARCH=$2 GOOS=$3 GOPROXY=https://goproxy.io CGO_ENABLED=${CGO} GOOS=${GOOS} GOARCH=${ARCH} go build -a -o resource-tagger cmd/server/server.go -GOPROXY=https://goproxy.io CGO_ENABLED=${CGO} GOOS=${GOOS} GOARCH=${ARCH} go build -a -o resource-tagger-client cmd/client/client.go diff --git a/build/dockerfile.metric-server b/observer-plugins/metric-server/Dockerfile similarity index 89% rename from build/dockerfile.metric-server rename to observer-plugins/metric-server/Dockerfile index d5e2552..d3ac9bf 100644 --- a/build/dockerfile.metric-server +++ b/observer-plugins/metric-server/Dockerfile @@ -8,7 +8,7 @@ ARG GOOS=linux WORKDIR /workspace # Copy the Go Modules manifests -COPY ../observer-plugins/metric-server . +COPY . . ## Copy the go source and vendor ## Build binary diff --git a/observer-plugins/metric-server/Makefile b/observer-plugins/metric-server/Makefile index d4d9dc1..23b7c8a 100644 --- a/observer-plugins/metric-server/Makefile +++ b/observer-plugins/metric-server/Makefile @@ -1,15 +1,15 @@ -REPOPROJECT := github.com/kube-arbiter/arbiter-plugins -EXEC := arbiter-metric-server -RELEASETAG := v0.0.1 +REPOPROJECT := kubearbiter +EXEC := observer-metric-server +RELEASETAG := v0.1.0 clean: rm -rf $(EXEC) -build: clean main.go server.go - CGO_ENABLED=0 GOOS=linux go build -o arbiter-metric-server main.go server.go metric_types.go +build: clean + CGO_ENABLED=0 GOOS=linux go build -o observer-metric-server main.go -build-image: build +build-image: docker build -t $(REPOPROJECT)/$(EXEC):$(RELEASETAG) . .DEFAULT_GOAL := build diff --git a/build/dockerfile.prometheus b/observer-plugins/prometheus/Dockerfile similarity index 92% rename from build/dockerfile.prometheus rename to observer-plugins/prometheus/Dockerfile index 99ca54e..ad9310e 100644 --- a/build/dockerfile.prometheus +++ b/observer-plugins/prometheus/Dockerfile @@ -8,7 +8,7 @@ ARG GOOS=linux WORKDIR /workspace # Copy the Go Modules manifests -COPY ../observer-plugins/prometheus . +COPY . . ## Copy the go source and vendor ## Build binary diff --git a/observer-plugins/prometheus/Makefile b/observer-plugins/prometheus/Makefile index 82b4770..22c78c0 100644 --- a/observer-plugins/prometheus/Makefile +++ b/observer-plugins/prometheus/Makefile @@ -1,15 +1,15 @@ -REPOPROJECT := github.com/kube-arbiter/arbiter-plugins -EXEC := arbiter-prometheus-server -RELEASETAG := v0.0.1 +REPOPROJECT := kubearbiter +EXEC := observer-prometheus-server +RELEASETAG := v0.1.0 clean: rm -rf $(EXEC) server main build: clean main.go - CGO_ENABLED=0 GOOS=linux go build -o arbiter-prometheus-server main.go + CGO_ENABLED=0 GOOS=linux go build -o observer-prometheus-server main.go build-image: build docker build -t $(REPOPROJECT)/$(EXEC):$(RELEASETAG) . -.DEFAULT_GOAL := build \ No newline at end of file +.DEFAULT_GOAL := build diff --git a/scripts/build.sh b/scripts/build.sh index 89cc54f..445fd8b 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -17,5 +17,5 @@ cd $ROOT/observer-plugins/prometheus; ./build-prometheus.sh $1 $2 $3 echo "build resource tagger" -cd $ROOT/resource-tagger-plugin +cd $ROOT/executor-plugins/resource-tagger ./build-resource-tagger.sh $1 $2 $3 diff --git a/scripts/clean.sh b/scripts/clean.sh index 7712165..d4485ae 100755 --- a/scripts/clean.sh +++ b/scripts/clean.sh @@ -1,9 +1,7 @@ #!/bin/bash ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.. -rm -rf $ROOT/observer-plugins/metric-server/arbiter-metric-server; -rm -rf $ROOT/observer-plugins/prometheus/arbiter-prometheus-server; -rm -rf $ROOT/resource-tagger-plugin/resource-tagger; -rm -rf $ROOT/resource-tagger-plugin/resource-tagger-client; -docker rmi arbiter/arbiter-metric-server:$1 arbiter/arbiter-prometheus-server:$1 arbiter/resource-tagger-plugin:$1 2> /dev/null || true; - +rm -rf $ROOT/observer-plugins/metric-server/observer-metric-server; +rm -rf $ROOT/observer-plugins/prometheus/observer-prometheus-server; +rm -rf $ROOT/executor-plugins/resource-tagger/resource-tagger; +docker rmi kubearbiter/observer-metric-server:$1 kubearbiter/observer-prometheus-server:$1 kubearbiter/executor-resource-tagger:$1 2> /dev/null || true; From 09a5189658567fb6a33f387f39cb494581be4cce Mon Sep 17 00:00:00 2001 From: nkwangleiGIT Date: Wed, 19 Oct 2022 17:05:21 +0800 Subject: [PATCH 2/5] Make executor more general to support more data of OAP --- executor-plugins/resource-tagger/README.md | 4 +- .../resource-tagger/cmd/server/server.go | 2 +- .../resource-tagger/doc/proto/index.html | 2 +- .../{execute.go => executor_wrapper.go} | 65 ++++++------------- .../internal/service/update_resource.go | 60 +++++++++++++++++ .../sample/resourcetagging-plugin.yaml | 2 +- 6 files changed, 86 insertions(+), 49 deletions(-) rename executor-plugins/resource-tagger/internal/service/{execute.go => executor_wrapper.go} (55%) create mode 100644 executor-plugins/resource-tagger/internal/service/update_resource.go diff --git a/executor-plugins/resource-tagger/README.md b/executor-plugins/resource-tagger/README.md index a8d3a57..bdeb329 100644 --- a/executor-plugins/resource-tagger/README.md +++ b/executor-plugins/resource-tagger/README.md @@ -19,6 +19,8 @@ To implement a plugin, you only need to implement a `Grpc` interface. The interf ```protobuf syntax = "proto3"; +import "k8s.io/apimachinery/pkg/runtime/generated.proto"; + package execute; option go_package = "lib/executor"; @@ -37,7 +39,7 @@ message ExecuteMessage { string namespace = 3; double exprVal = 4; bool condVal = 5; - map parameters = 6; + optional k8s.io.apimachinery.pkg.runtime.RawExtension actionData = 6; string group = 7; string version = 8; string resources = 9; diff --git a/executor-plugins/resource-tagger/cmd/server/server.go b/executor-plugins/resource-tagger/cmd/server/server.go index b48d9aa..f666306 100644 --- a/executor-plugins/resource-tagger/cmd/server/server.go +++ b/executor-plugins/resource-tagger/cmd/server/server.go @@ -59,6 +59,6 @@ func main() { pb.RegisterExecuteServer(server, execute) - klog.Infoln("resourcetagger server started...") + klog.Infoln("resource-tagger plugin started...") server.Serve(listener) } diff --git a/executor-plugins/resource-tagger/doc/proto/index.html b/executor-plugins/resource-tagger/doc/proto/index.html index 449e140..49502ee 100644 --- a/executor-plugins/resource-tagger/doc/proto/index.html +++ b/executor-plugins/resource-tagger/doc/proto/index.html @@ -251,7 +251,7 @@

ExecuteMessage

- parameters + actionData ExecuteMessage.ParametersEntry repeated

diff --git a/executor-plugins/resource-tagger/internal/service/execute.go b/executor-plugins/resource-tagger/internal/service/executor_wrapper.go similarity index 55% rename from executor-plugins/resource-tagger/internal/service/execute.go rename to executor-plugins/resource-tagger/internal/service/executor_wrapper.go index af88016..9e29100 100644 --- a/executor-plugins/resource-tagger/internal/service/execute.go +++ b/executor-plugins/resource-tagger/internal/service/executor_wrapper.go @@ -48,12 +48,10 @@ func NewExecuteService() pb.ExecuteServer { func (e *ExecuteServiceImpl) Execute(ctx context.Context, message *pb.ExecuteMessage) (*pb.ExecuteResponse, error) { klog.V(10).Infof("kubeconfig path: %s\n", *kubeconfig) - klog.V(10).Infof("ResourceName: %s, namespace: %s, exprval: %f, condval: %v, parameters: %v\n", - message.ResourceName, message.Namespace, message.ExprVal, message.CondVal, message.Parameters) + klog.V(4).Infof("ResourceName: %s, namespace: %s, exprval: %f, condval: %v, actionData: %v\n", + message.ResourceName, message.Namespace, message.ExprVal, message.CondVal, message.ActionData) resourceBaseFormat := fmt.Sprintf("%s/%s/%s:%s", message.Group, message.Version, message.Resources, message.ResourceName) - klog.Infof("start processing label changes for resource %s", resourceBaseFormat) - var ( config *rest.Config err error @@ -72,63 +70,40 @@ func (e *ExecuteServiceImpl) Execute(ctx context.Context, message *pb.ExecuteMes panic(err) } - var ( - u *unstructured.Unstructured - ) - - r := &pb.ExecuteResponse{ + var resouceToUpdate *unstructured.Unstructured + response := &pb.ExecuteResponse{ Data: "", } namespaceableInterface := dynamicClient.Resource( schema.GroupVersionResource{Group: message.Group, Version: message.Version, Resource: message.Resources}) if message.Namespace != "" { - u, err = namespaceableInterface.Namespace(message.Namespace).Get(context.Background(), message.ResourceName, metav1.GetOptions{}) + resouceToUpdate, err = namespaceableInterface.Namespace(message.Namespace).Get(context.Background(), message.ResourceName, metav1.GetOptions{}) } else { - u, err = namespaceableInterface.Get(context.Background(), message.ResourceName, metav1.GetOptions{}) + resouceToUpdate, err = namespaceableInterface.Get(context.Background(), message.ResourceName, metav1.GetOptions{}) } if err != nil { klog.Errorf("get resource %s (int namespace %s) error: %s\n", resourceBaseFormat, message.Namespace, err) if errors.IsNotFound(err) { - r.Data = fmt.Sprintf("Resource %s not found in namespace %s", resourceBaseFormat, message.Namespace) - return r, nil + response.Data = fmt.Sprintf("Resource %s not found in namespace %s", resourceBaseFormat, message.Namespace) + return response, nil } - r.Data = fmt.Sprintf("get resource %s error: %s", resourceBaseFormat, err) - return r, err - } - annotations := u.GetAnnotations() - labels := u.GetLabels() - if annotations == nil { - annotations = make(map[string]string) - } - if labels == nil { - labels = make(map[string]string) + response.Data = fmt.Sprintf("get resource %s error: %s", resourceBaseFormat, err) + return response, err } - - if message.CondVal { - r.Data = fmt.Sprintf("Resource %s in namesapce '%s' is tagged", resourceBaseFormat, message.Namespace) - annotations[message.Parameters["tagging-key"]] = message.Parameters["tagging-value"] - labels[message.Parameters["tagging-key"]] = message.Parameters["tagging-value"] - klog.V(10).Infof("after adding, the annotation %v, the labels %v\n", annotations, labels) - } else { - r.Data = fmt.Sprintf("Resource %s in namespace '%s' is untagged", resourceBaseFormat, message.Namespace) - delete(annotations, message.Parameters["tagging-key"]) - delete(labels, message.Parameters["tagging-key"]) - klog.V(10).Infof("after deleting, the annotations %v, the labels %v\n", annotations, labels) + // Let the custom code to handle how to update the resource + err = e.updateResource(resouceToUpdate, message) + if err != nil { + response.Data = err.Error() + return response, err } - u.SetLabels(labels) - u.SetAnnotations(annotations) - if message.Namespace != "" { - _, err = namespaceableInterface.Namespace(message.Namespace).Update(context.Background(), u, metav1.UpdateOptions{}) + _, err = namespaceableInterface.Namespace(message.Namespace).Update(context.Background(), resouceToUpdate, metav1.UpdateOptions{}) } else { - _, err = namespaceableInterface.Update(context.Background(), u, metav1.UpdateOptions{}) + _, err = namespaceableInterface.Update(context.Background(), resouceToUpdate, metav1.UpdateOptions{}) } - if err != nil { - r.Data = fmt.Sprintf("update resource %s error: %s", resourceBaseFormat, err) - return r, err + response.Data = fmt.Sprintf("update resource %s error: %s", resourceBaseFormat, err) + return response, err } - - klog.Infof("%s processing completed", resourceBaseFormat) - return r, nil + return response, nil } diff --git a/executor-plugins/resource-tagger/internal/service/update_resource.go b/executor-plugins/resource-tagger/internal/service/update_resource.go new file mode 100644 index 0000000..cf741a1 --- /dev/null +++ b/executor-plugins/resource-tagger/internal/service/update_resource.go @@ -0,0 +1,60 @@ +/* +Copyright 2022 The Arbiter Authors. + +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 service + +import ( + "fmt" + + pb "github.com/kube-arbiter/arbiter/pkg/proto/lib/executor" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/util/json" + "k8s.io/klog/v2" +) + +/* +actionData defines the resource passed to the plugins, it can have arbitrary structure +You can use the .Raw data, and marshel a json object +*/ +func (e *ExecuteServiceImpl) updateResource(resouceToUpdate *unstructured.Unstructured, message *pb.ExecuteMessage) (err error) { + resourceName := fmt.Sprintf("%s/%s", resouceToUpdate.GetKind(), resouceToUpdate.GetName()) + klog.Infof("start processing resource %s", resourceName) + + metaObj := metav1.ObjectMeta{} + if err = json.Unmarshal(message.ActionData.Raw, &metaObj); err != nil { + klog.Errorf("Failed to unmarshal the raw message %s with error %s", message.ActionData.Raw, err) + return err + } + labels := resouceToUpdate.GetLabels() + if message.CondVal { + if labels == nil { + labels = make(map[string]string) + } + for key, value := range metaObj.Labels { + labels[key] = value + } + klog.Infof("Resource %s in namesapce '%s' is labeled", resourceName, message.Namespace) + } else { + for key, _ := range metaObj.Labels { + delete(labels, key) + } + klog.Infof("Resource %s in namespace '%s' is un-labeled", resourceName, message.Namespace) + } + resouceToUpdate.SetLabels(labels) + klog.Infof("%s updated successfully.", resourceName) + return nil +} diff --git a/executor-plugins/resource-tagger/sample/resourcetagging-plugin.yaml b/executor-plugins/resource-tagger/sample/resourcetagging-plugin.yaml index 826417d..34135e5 100644 --- a/executor-plugins/resource-tagger/sample/resourcetagging-plugin.yaml +++ b/executor-plugins/resource-tagger/sample/resourcetagging-plugin.yaml @@ -22,7 +22,7 @@ spec: containers: - command: - /resource-tagger - image: 172.22.50.227/arbiter/resource-tagger-plugin:v0.0.1 + image: kubearbiter/executor-resource-tagger:v0.1.0 name: resource-tagger securityContext: allowPrivilegeEscalation: false From 1b7df8e98b23f88b20be4d1b6a8cbe3ac1ffe281 Mon Sep 17 00:00:00 2001 From: nkwangleiGIT Date: Wed, 19 Oct 2022 23:05:36 +0800 Subject: [PATCH 3/5] Remove staging and refine code --- executor-plugins/resource-tagger/go.mod | 2 +- executor-plugins/resource-tagger/go.sum | 4 +- .../internal/service/update_resource.go | 2 +- .../github.com/kube-arbiter/arbiter/LICENSE | 203 ---------- .../github.com/kube-arbiter/arbiter/go.mod | 3 - .../kube-arbiter/arbiter/pkg/proto/LICENSE | 339 ----------------- .../pkg/proto/lib/executor/execute.pb.go | 350 ------------------ .../pkg/proto/lib/executor/execute_grpc.pb.go | 105 ------ .../metric-server/server/server.go | 1 + 9 files changed, 5 insertions(+), 1004 deletions(-) delete mode 100644 executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/LICENSE delete mode 100644 executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/go.mod delete mode 100644 executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/pkg/proto/LICENSE delete mode 100644 executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/pkg/proto/lib/executor/execute.pb.go delete mode 100644 executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/pkg/proto/lib/executor/execute_grpc.pb.go diff --git a/executor-plugins/resource-tagger/go.mod b/executor-plugins/resource-tagger/go.mod index 4a0787e..3d21382 100644 --- a/executor-plugins/resource-tagger/go.mod +++ b/executor-plugins/resource-tagger/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/golang/protobuf v1.5.2 - github.com/kube-arbiter/arbiter v0.1.0 + github.com/kube-arbiter/arbiter v0.1.1-0.20221019145918-1199780f119f github.com/pseudomuto/protoc-gen-doc v1.5.1 google.golang.org/grpc v1.47.0 k8s.io/apimachinery v0.24.2 diff --git a/executor-plugins/resource-tagger/go.sum b/executor-plugins/resource-tagger/go.sum index 67182b3..0d44565 100644 --- a/executor-plugins/resource-tagger/go.sum +++ b/executor-plugins/resource-tagger/go.sum @@ -220,8 +220,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kube-arbiter/arbiter v0.1.0 h1:tEmK49zMn8x8Qv2f27mUNj7U/cOLbHnMAeM3A9ThuBg= -github.com/kube-arbiter/arbiter v0.1.0/go.mod h1:jIDm2IdlPwhV/6kbUIhak9wkV3jgwBBDoPeIuZSZsxo= +github.com/kube-arbiter/arbiter v0.1.1-0.20221019145918-1199780f119f h1:G30u8GY/sgXWmEnjsYIWU72dgaRMS9amZVrmA1qhOHM= +github.com/kube-arbiter/arbiter v0.1.1-0.20221019145918-1199780f119f/go.mod h1:jIDm2IdlPwhV/6kbUIhak9wkV3jgwBBDoPeIuZSZsxo= github.com/lyft/protoc-gen-star v0.6.0/go.mod h1:TGAoBVkt8w7MPG72TrKIu85MIdXwDuzJYeZuUPFPNwA= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= diff --git a/executor-plugins/resource-tagger/internal/service/update_resource.go b/executor-plugins/resource-tagger/internal/service/update_resource.go index cf741a1..d9a9878 100644 --- a/executor-plugins/resource-tagger/internal/service/update_resource.go +++ b/executor-plugins/resource-tagger/internal/service/update_resource.go @@ -49,7 +49,7 @@ func (e *ExecuteServiceImpl) updateResource(resouceToUpdate *unstructured.Unstru } klog.Infof("Resource %s in namesapce '%s' is labeled", resourceName, message.Namespace) } else { - for key, _ := range metaObj.Labels { + for key := range metaObj.Labels { delete(labels, key) } klog.Infof("Resource %s in namespace '%s' is un-labeled", resourceName, message.Namespace) diff --git a/executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/LICENSE b/executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/LICENSE deleted file mode 100644 index fd08d4d..0000000 --- a/executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/LICENSE +++ /dev/null @@ -1,203 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright (C) 2021 The Crane Authors & THL A29 Limited, a Tencent company. - - 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. - - Other dependencies and licenses: Please refer to file LICENSES/OTHER_LICENSES diff --git a/executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/go.mod b/executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/go.mod deleted file mode 100644 index 45ad463..0000000 --- a/executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/kube-arbiter/arbiter - -go 1.18 diff --git a/executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/pkg/proto/LICENSE b/executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/pkg/proto/LICENSE deleted file mode 100644 index d159169..0000000 --- a/executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/pkg/proto/LICENSE +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/pkg/proto/lib/executor/execute.pb.go b/executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/pkg/proto/lib/executor/execute.pb.go deleted file mode 100644 index 5603dbd..0000000 --- a/executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/pkg/proto/lib/executor/execute.pb.go +++ /dev/null @@ -1,350 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.28.0 -// protoc v3.19.4 -// source: execute.proto - -package executor - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Kind int32 - -const ( - Kind_pod Kind = 0 - Kind_node Kind = 1 -) - -// Enum value maps for Kind. -var ( - Kind_name = map[int32]string{ - 0: "pod", - 1: "node", - } - Kind_value = map[string]int32{ - "pod": 0, - "node": 1, - } -) - -func (x Kind) Enum() *Kind { - p := new(Kind) - *p = x - return p -} - -func (x Kind) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (Kind) Descriptor() protoreflect.EnumDescriptor { - return file_execute_proto_enumTypes[0].Descriptor() -} - -func (Kind) Type() protoreflect.EnumType { - return &file_execute_proto_enumTypes[0] -} - -func (x Kind) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Use Kind.Descriptor instead. -func (Kind) EnumDescriptor() ([]byte, []int) { - return file_execute_proto_rawDescGZIP(), []int{0} -} - -type ExecuteMessage struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - ResourceName string `protobuf:"bytes,1,opt,name=resourceName,proto3" json:"resourceName,omitempty"` - Kind Kind `protobuf:"varint,2,opt,name=kind,proto3,enum=execute.Kind" json:"kind,omitempty"` - Namespace string `protobuf:"bytes,3,opt,name=namespace,proto3" json:"namespace,omitempty"` - ExprVal float64 `protobuf:"fixed64,4,opt,name=exprVal,proto3" json:"exprVal,omitempty"` - CondVal bool `protobuf:"varint,5,opt,name=condVal,proto3" json:"condVal,omitempty"` - Parameters map[string]string `protobuf:"bytes,6,rep,name=parameters,proto3" json:"parameters,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - Group string `protobuf:"bytes,7,opt,name=group,proto3" json:"group,omitempty"` - Version string `protobuf:"bytes,8,opt,name=version,proto3" json:"version,omitempty"` - Resources string `protobuf:"bytes,9,opt,name=resources,proto3" json:"resources,omitempty"` -} - -func (x *ExecuteMessage) Reset() { - *x = ExecuteMessage{} - if protoimpl.UnsafeEnabled { - mi := &file_execute_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ExecuteMessage) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ExecuteMessage) ProtoMessage() {} - -func (x *ExecuteMessage) ProtoReflect() protoreflect.Message { - mi := &file_execute_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ExecuteMessage.ProtoReflect.Descriptor instead. -func (*ExecuteMessage) Descriptor() ([]byte, []int) { - return file_execute_proto_rawDescGZIP(), []int{0} -} - -func (x *ExecuteMessage) GetResourceName() string { - if x != nil { - return x.ResourceName - } - return "" -} - -func (x *ExecuteMessage) GetKind() Kind { - if x != nil { - return x.Kind - } - return Kind_pod -} - -func (x *ExecuteMessage) GetNamespace() string { - if x != nil { - return x.Namespace - } - return "" -} - -func (x *ExecuteMessage) GetExprVal() float64 { - if x != nil { - return x.ExprVal - } - return 0 -} - -func (x *ExecuteMessage) GetCondVal() bool { - if x != nil { - return x.CondVal - } - return false -} - -func (x *ExecuteMessage) GetParameters() map[string]string { - if x != nil { - return x.Parameters - } - return nil -} - -func (x *ExecuteMessage) GetGroup() string { - if x != nil { - return x.Group - } - return "" -} - -func (x *ExecuteMessage) GetVersion() string { - if x != nil { - return x.Version - } - return "" -} - -func (x *ExecuteMessage) GetResources() string { - if x != nil { - return x.Resources - } - return "" -} - -type ExecuteResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Data string `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` -} - -func (x *ExecuteResponse) Reset() { - *x = ExecuteResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_execute_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ExecuteResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ExecuteResponse) ProtoMessage() {} - -func (x *ExecuteResponse) ProtoReflect() protoreflect.Message { - mi := &file_execute_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ExecuteResponse.ProtoReflect.Descriptor instead. -func (*ExecuteResponse) Descriptor() ([]byte, []int) { - return file_execute_proto_rawDescGZIP(), []int{1} -} - -func (x *ExecuteResponse) GetData() string { - if x != nil { - return x.Data - } - return "" -} - -var File_execute_proto protoreflect.FileDescriptor - -var file_execute_proto_rawDesc = []byte{ - 0x0a, 0x0d, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, - 0x07, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x22, 0xff, 0x02, 0x0a, 0x0e, 0x45, 0x78, 0x65, - 0x63, 0x75, 0x74, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x72, - 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x0c, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, - 0x21, 0x0a, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0d, 0x2e, - 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x2e, 0x4b, 0x69, 0x6e, 0x64, 0x52, 0x04, 0x6b, 0x69, - 0x6e, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, - 0x12, 0x18, 0x0a, 0x07, 0x65, 0x78, 0x70, 0x72, 0x56, 0x61, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x01, 0x52, 0x07, 0x65, 0x78, 0x70, 0x72, 0x56, 0x61, 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, - 0x6e, 0x64, 0x56, 0x61, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x63, 0x6f, 0x6e, - 0x64, 0x56, 0x61, 0x6c, 0x12, 0x47, 0x0a, 0x0a, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, - 0x72, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x65, 0x78, 0x65, 0x63, 0x75, - 0x74, 0x65, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x2e, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, - 0x79, 0x52, 0x0a, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x12, 0x14, 0x0a, - 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x67, 0x72, - 0x6f, 0x75, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x08, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1c, 0x0a, - 0x09, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x09, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x1a, 0x3d, 0x0a, 0x0f, 0x50, - 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, - 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, - 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x25, 0x0a, 0x0f, 0x45, 0x78, - 0x65, 0x63, 0x75, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, - 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, - 0x61, 0x2a, 0x19, 0x0a, 0x04, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x07, 0x0a, 0x03, 0x70, 0x6f, 0x64, - 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x6e, 0x6f, 0x64, 0x65, 0x10, 0x01, 0x32, 0x49, 0x0a, 0x07, - 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x12, 0x3e, 0x0a, 0x07, 0x45, 0x78, 0x65, 0x63, 0x75, - 0x74, 0x65, 0x12, 0x17, 0x2e, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x2e, 0x45, 0x78, 0x65, - 0x63, 0x75, 0x74, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x18, 0x2e, 0x65, 0x78, - 0x65, 0x63, 0x75, 0x74, 0x65, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0e, 0x5a, 0x0c, 0x6c, 0x69, 0x62, 0x2f, 0x65, - 0x78, 0x65, 0x63, 0x75, 0x74, 0x6f, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_execute_proto_rawDescOnce sync.Once - file_execute_proto_rawDescData = file_execute_proto_rawDesc -) - -func file_execute_proto_rawDescGZIP() []byte { - file_execute_proto_rawDescOnce.Do(func() { - file_execute_proto_rawDescData = protoimpl.X.CompressGZIP(file_execute_proto_rawDescData) - }) - return file_execute_proto_rawDescData -} - -var file_execute_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_execute_proto_msgTypes = make([]protoimpl.MessageInfo, 3) -var file_execute_proto_goTypes = []interface{}{ - (Kind)(0), // 0: execute.Kind - (*ExecuteMessage)(nil), // 1: execute.ExecuteMessage - (*ExecuteResponse)(nil), // 2: execute.ExecuteResponse - nil, // 3: execute.ExecuteMessage.ParametersEntry -} -var file_execute_proto_depIdxs = []int32{ - 0, // 0: execute.ExecuteMessage.kind:type_name -> execute.Kind - 3, // 1: execute.ExecuteMessage.parameters:type_name -> execute.ExecuteMessage.ParametersEntry - 1, // 2: execute.Execute.Execute:input_type -> execute.ExecuteMessage - 2, // 3: execute.Execute.Execute:output_type -> execute.ExecuteResponse - 3, // [3:4] is the sub-list for method output_type - 2, // [2:3] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name -} - -func init() { file_execute_proto_init() } -func file_execute_proto_init() { - if File_execute_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_execute_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ExecuteMessage); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_execute_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ExecuteResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_execute_proto_rawDesc, - NumEnums: 1, - NumMessages: 3, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_execute_proto_goTypes, - DependencyIndexes: file_execute_proto_depIdxs, - EnumInfos: file_execute_proto_enumTypes, - MessageInfos: file_execute_proto_msgTypes, - }.Build() - File_execute_proto = out.File - file_execute_proto_rawDesc = nil - file_execute_proto_goTypes = nil - file_execute_proto_depIdxs = nil -} diff --git a/executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/pkg/proto/lib/executor/execute_grpc.pb.go b/executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/pkg/proto/lib/executor/execute_grpc.pb.go deleted file mode 100644 index 770e9d8..0000000 --- a/executor-plugins/resource-tagger/staging/github.com/kube-arbiter/arbiter/pkg/proto/lib/executor/execute_grpc.pb.go +++ /dev/null @@ -1,105 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.2.0 -// - protoc v3.19.4 -// source: execute.proto - -package executor - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -// ExecuteClient is the client API for Execute service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type ExecuteClient interface { - Execute(ctx context.Context, in *ExecuteMessage, opts ...grpc.CallOption) (*ExecuteResponse, error) -} - -type executeClient struct { - cc grpc.ClientConnInterface -} - -func NewExecuteClient(cc grpc.ClientConnInterface) ExecuteClient { - return &executeClient{cc} -} - -func (c *executeClient) Execute(ctx context.Context, in *ExecuteMessage, opts ...grpc.CallOption) (*ExecuteResponse, error) { - out := new(ExecuteResponse) - err := c.cc.Invoke(ctx, "/execute.Execute/Execute", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// ExecuteServer is the server API for Execute service. -// All implementations must embed UnimplementedExecuteServer -// for forward compatibility -type ExecuteServer interface { - Execute(context.Context, *ExecuteMessage) (*ExecuteResponse, error) - mustEmbedUnimplementedExecuteServer() -} - -// UnimplementedExecuteServer must be embedded to have forward compatible implementations. -type UnimplementedExecuteServer struct { -} - -func (UnimplementedExecuteServer) Execute(context.Context, *ExecuteMessage) (*ExecuteResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Execute not implemented") -} -func (UnimplementedExecuteServer) mustEmbedUnimplementedExecuteServer() {} - -// UnsafeExecuteServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to ExecuteServer will -// result in compilation errors. -type UnsafeExecuteServer interface { - mustEmbedUnimplementedExecuteServer() -} - -func RegisterExecuteServer(s grpc.ServiceRegistrar, srv ExecuteServer) { - s.RegisterService(&Execute_ServiceDesc, srv) -} - -func _Execute_Execute_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ExecuteMessage) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ExecuteServer).Execute(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/execute.Execute/Execute", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ExecuteServer).Execute(ctx, req.(*ExecuteMessage)) - } - return interceptor(ctx, in, info, handler) -} - -// Execute_ServiceDesc is the grpc.ServiceDesc for Execute service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var Execute_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "execute.Execute", - HandlerType: (*ExecuteServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Execute", - Handler: _Execute_Execute_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "execute.proto", -} diff --git a/observer-plugins/metric-server/server/server.go b/observer-plugins/metric-server/server/server.go index 6ff3115..0eab16a 100644 --- a/observer-plugins/metric-server/server/server.go +++ b/observer-plugins/metric-server/server/server.go @@ -105,6 +105,7 @@ func (s *server) GetMetrics(ctx context.Context, req *obi.GetMetricsRequest) (*o queryPath := fmt.Sprintf(nodeMetricAPI, req.ResourceNames[0]) nodeMetricBytes, err := s.client.RESTClient().Get().AbsPath(queryPath).DoRaw(ctx) if err != nil { + klog.Errorf("[Error] failed to get node metric from metric-server: %s\n", err) return returnOjb, err } nodeMetric := NodeMetrics{} From 132a4f1e30f93d0a68fc36788d9baca4f90988a8 Mon Sep 17 00:00:00 2001 From: nkwangleiGIT Date: Fri, 21 Oct 2022 16:50:48 +0800 Subject: [PATCH 4/5] Support get metric for general pql that doesn't depend pod/node resource --- observer-plugins/metric-server/main.go | 33 ++++++++++++++++++- observer-plugins/prometheus/main.go | 32 +++++++++++++++++- .../prometheus/prometheus/prometheus.go | 30 ++++++++++++----- .../prometheus/prometheus/server.go | 16 +++++---- 4 files changed, 94 insertions(+), 17 deletions(-) diff --git a/observer-plugins/metric-server/main.go b/observer-plugins/metric-server/main.go index 9b5c94d..ed320d9 100644 --- a/observer-plugins/metric-server/main.go +++ b/observer-plugins/metric-server/main.go @@ -20,6 +20,9 @@ import ( "flag" "log" "net" + "os" + "os/signal" + "syscall" "k8s.io/client-go/kubernetes" @@ -38,6 +41,9 @@ var ( endpoint = flag.String("endpoint", "/var/run/observer.sock", "unix socket domain for current server") kubeconfig = flag.String("kubeconfig", "", "kubernetes auth config file") ) +var ( + shutdownSignals = []os.Signal{os.Interrupt, syscall.SIGTERM} +) func main() { klog.InitFlags(flag.CommandLine) @@ -62,8 +68,11 @@ func main() { if err != nil { log.Fatalf("%s create metric client error: %s", server.PluginName, err) } - metricServer := grpc.NewServer() + // Setup signal watcher to handle cleanup + SetupSignalHandler(*endpoint) + + metricServer := grpc.NewServer() obi.RegisterServerServer(metricServer, server.NewServer(clientSet)) listen, err := net.Listen("unix", *endpoint) if err != nil { @@ -73,3 +82,25 @@ func main() { metricServer.Serve(listen) } + +// SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned +// which is closed on one of these signals. If a second signal is caught, the program +// is terminated with exit code 1. +func SetupSignalHandler(socketFile string) { + c := make(chan os.Signal) + signal.Notify(c, shutdownSignals...) + go func() { + for s := range c { + switch s { + case os.Interrupt, syscall.SIGTERM: + klog.Infoln("Shutting down normally...") + if err := os.RemoveAll(socketFile); err != nil { + klog.Fatal(err) + } + os.Exit(1) + default: + klog.Infoln("Got signal", s) + } + } + }() +} diff --git a/observer-plugins/prometheus/main.go b/observer-plugins/prometheus/main.go index c1731cc..c8e2c1c 100644 --- a/observer-plugins/prometheus/main.go +++ b/observer-plugins/prometheus/main.go @@ -20,6 +20,9 @@ import ( "flag" "log" "net" + "os" + "os/signal" + "syscall" "github.com/kube-arbiter/arbiter-plugins/observer-plugins/prometheus/prometheus" obi "github.com/kube-arbiter/arbiter/pkg/proto/lib/observer" @@ -37,6 +40,9 @@ var ( stepSeconds = flag.Int64("step", 60, "query steps") rangeMinute = flag.Int64("range", 2, "prometheus, the maximum time between two slices within the boundaries.") ) +var ( + shutdownSignals = []os.Signal{os.Interrupt, syscall.SIGTERM} +) func main() { klog.InitFlags(flag.CommandLine) @@ -63,6 +69,8 @@ func main() { if err != nil { klog.Fatal(err) } + // Setup signal watcher to handle cleanup + SetupSignalHandler(*endpoint) server := grpc.NewServer() obi.RegisterServerServer(server, prometheus.NewPrometheusServer(*address, conf, *stepSeconds, *rangeMinute)) @@ -71,6 +79,28 @@ func main() { log.Fatal(err) } - klog.Infof("%s starting work...", prometheus.PluginName) + klog.Infof("%s plugin started ...", prometheus.PluginName) server.Serve(listen) } + +// SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned +// which is closed on one of these signals. If a second signal is caught, the program +// is terminated with exit code 1. +func SetupSignalHandler(socketFile string) { + c := make(chan os.Signal) + signal.Notify(c, shutdownSignals...) + go func() { + for s := range c { + switch s { + case os.Interrupt, syscall.SIGTERM: + klog.Infoln("Shutting down normally...") + if err := os.RemoveAll(socketFile); err != nil { + klog.Fatal(err) + } + os.Exit(1) + default: + klog.Infoln("Got signal", s) + } + } + }() +} diff --git a/observer-plugins/prometheus/prometheus/prometheus.go b/observer-plugins/prometheus/prometheus/prometheus.go index 5c9f8c8..dfee9f4 100644 --- a/observer-plugins/prometheus/prometheus/prometheus.go +++ b/observer-plugins/prometheus/prometheus/prometheus.go @@ -17,6 +17,7 @@ limitations under the License. package prometheus import ( + "encoding/json" "fmt" "time" @@ -65,7 +66,7 @@ type CalculateAux struct { Value float64 } -func (p *prometheusServer) Query(startTime, endTime time.Time, query, op string) (DataSeries, error) { +func (p *prometheusServer) Query(startTime, endTime time.Time, kind, query, op string) (DataSeries, error) { method := "prometheusServer.Query" ans := DataSeries{Timestamp: endTime.UnixMilli()} prometheusAPI, err := p.NewPrometheusAPI() @@ -86,18 +87,29 @@ func (p *prometheusServer) Query(startTime, endTime time.Time, query, op string) klog.V(4).Infof("%s quer '%s' result with warnings %v\n", method, warnings) } - data, err := formatRawValues(result, op) - if err != nil { - return ans, err - } - - if f, ok := actionFuncs[op]; ok { - f(data, &ans) + // TODO: Use kind as the raw data query, may add a 'rawData: true' property for this? + if kind == "Pod" || kind == "Node" { + data, err := formatRawValues(result) + if err != nil { + return ans, err + } + if f, ok := actionFuncs[op]; ok { + f(data, &ans) + } + } else { + // Handle raw data if no aggregation defined, just return the json data + jsonValue, err := json.Marshal(result) + if err != nil { + klog.Errorf("failed to marshal result to json: %s", err) + ans.Value = fmt.Sprintf("failed to get json value: %s " + result.String()) + } else { + ans.Value = string(jsonValue) + } } return ans, nil } -func formatRawValues(rawValue model.Value, op string) ([]CalculateAux, error) { +func formatRawValues(rawValue model.Value) ([]CalculateAux, error) { ans := make([]CalculateAux, 0) switch rawValue.Type() { case model.ValScalar: diff --git a/observer-plugins/prometheus/prometheus/server.go b/observer-plugins/prometheus/prometheus/server.go index dad95b1..9d620f9 100644 --- a/observer-plugins/prometheus/prometheus/server.go +++ b/observer-plugins/prometheus/prometheus/server.go @@ -31,6 +31,7 @@ const ( MaxAction = "max" MinAction = "min" AvgAction = "avg" + NoneAction = "none" ) // impl obi interface @@ -77,24 +78,27 @@ func (p *prometheusServer) GetMetrics(ctx context.Context, req *obi.GetMetricsRe var err error klog.V(4).Infof("prometheus query: %s\n", req.Query) + var resourceName string + if len(req.ResourceNames) > 0 { + resourceName = req.ResourceNames[0] + } result := &obi.GetMetricsResponse{ - ResourceName: req.ResourceNames[0], + ResourceName: resourceName, Namespace: req.Namespace, Unit: req.Unit, Records: []*obi.GetMetricsResponseRecord{}, } + // use avgerage as the default aggregation action op := AvgAction if len(req.Aggregation) > 0 { op = req.Aggregation[0] } - klog.Infof("exec aggregation is: %s\n", op) - metricData, err := p.Query(startTime, endTime, req.Query, op) + metricData, err := p.Query(startTime, endTime, req.Kind, req.Query, op) if err != nil { klog.Errorf("%s query error: %s\n", method, err) return result, err } - // only return the latest record result.Records = append(result.Records, &obi.GetMetricsResponseRecord{Timestamp: metricData.Timestamp, Value: metricData.Value}) /* @@ -103,8 +107,8 @@ func (p *prometheusServer) GetMetrics(ctx context.Context, req *obi.GetMetricsRe } */ - klog.Infof("query by %s successfully", req.MetricName) - klog.V(5).Infof("%s query by %s result: %v\n", method, req.MetricName, metricData) + klog.Infof("query by metric '%s', query '%s' successfully", req.MetricName, req.Query) + klog.V(5).Infof("%s query by %s, %s result: %v\n", method, req.MetricName, req.Query, metricData) return result, nil } From 9afb1d2cb41f10e40df8c939e74879c665815559 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 21 Oct 2022 08:57:04 +0000 Subject: [PATCH 5/5] build(deps): bump k8s.io/apimachinery Bumps [k8s.io/apimachinery](https://github.com/kubernetes/apimachinery) from 0.24.2 to 0.25.3. - [Release notes](https://github.com/kubernetes/apimachinery/releases) - [Commits](https://github.com/kubernetes/apimachinery/compare/v0.24.2...v0.25.3) --- updated-dependencies: - dependency-name: k8s.io/apimachinery dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- executor-plugins/resource-tagger/go.mod | 13 +++++++------ executor-plugins/resource-tagger/go.sum | 23 +++++++++++++++-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/executor-plugins/resource-tagger/go.mod b/executor-plugins/resource-tagger/go.mod index 3d21382..c25f3b7 100644 --- a/executor-plugins/resource-tagger/go.mod +++ b/executor-plugins/resource-tagger/go.mod @@ -7,9 +7,9 @@ require ( github.com/kube-arbiter/arbiter v0.1.1-0.20221019145918-1199780f119f github.com/pseudomuto/protoc-gen-doc v1.5.1 google.golang.org/grpc v1.47.0 - k8s.io/apimachinery v0.24.2 + k8s.io/apimachinery v0.25.3 k8s.io/client-go v0.24.2 - k8s.io/klog/v2 v2.60.1 + k8s.io/klog/v2 v2.70.1 ) require ( @@ -17,8 +17,9 @@ require ( github.com/Masterminds/semver v1.5.0 // indirect github.com/Masterminds/sprig v2.22.0+incompatible // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/emicklei/go-restful/v3 v3.9.0 // indirect github.com/envoyproxy/protoc-gen-validate v0.6.7 // indirect - github.com/go-logr/logr v1.2.0 // indirect + github.com/go-logr/logr v1.2.3 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/google/gofuzz v1.1.0 // indirect github.com/google/uuid v1.3.0 // indirect @@ -44,8 +45,8 @@ require ( google.golang.org/protobuf v1.28.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect - sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect - sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect + k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect + sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect + sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/executor-plugins/resource-tagger/go.sum b/executor-plugins/resource-tagger/go.sum index 0d44565..e86cb29 100644 --- a/executor-plugins/resource-tagger/go.sum +++ b/executor-plugins/resource-tagger/go.sum @@ -79,8 +79,9 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= -github.com/emicklei/go-restful v2.9.5+incompatible h1:spTtZBk5DYEvbxMVutUuTyh1Ao2r4iyvLdACqsl/Ljk= github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= +github.com/emicklei/go-restful/v3 v3.9.0 h1:XwGDlfxEnQZzuopoqxwSEllNcCOM9DhhFyhFIIGKwxE= +github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -102,8 +103,9 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2 github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= -github.com/go-logr/logr v1.2.0 h1:QK40JKJyMdUDz+h+xvCsru/bJhvG0UxvePV0ufL/AcE= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= +github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= @@ -669,28 +671,33 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9 honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= k8s.io/api v0.24.2 h1:g518dPU/L7VRLxWfcadQn2OnsiGWVOadTLpdnqgY2OI= k8s.io/api v0.24.2/go.mod h1:AHqbSkTm6YrQ0ObxjO3Pmp/ubFF/KuM7jU+3khoBsOg= -k8s.io/apimachinery v0.24.2 h1:5QlH9SL2C8KMcrNJPor+LbXVTaZRReml7svPEh4OKDM= k8s.io/apimachinery v0.24.2/go.mod h1:82Bi4sCzVBdpYjyI4jY6aHX+YCUchUIrZrXKedjd2UM= +k8s.io/apimachinery v0.25.3 h1:7o9ium4uyUOM76t6aunP0nZuex7gDf8VGwkR5RcJnQc= +k8s.io/apimachinery v0.25.3/go.mod h1:jaF9C/iPNM1FuLl7Zuy5b9v+n35HGSh6AQ4HYRkCqwo= k8s.io/client-go v0.24.2 h1:CoXFSf8if+bLEbinDqN9ePIDGzcLtqhfd6jpfnwGOFA= k8s.io/client-go v0.24.2/go.mod h1:zg4Xaoo+umDsfCWr4fCnmLEtQXyCNXCvJuSsglNcV30= k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= -k8s.io/klog/v2 v2.60.1 h1:VW25q3bZx9uE3vvdL6M8ezOX79vA2Aq1nEWLqNQclHc= k8s.io/klog/v2 v2.60.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= -k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 h1:Gii5eqf+GmIEwGNKQYQClCayuJCe2/4fZUvF7VG99sU= +k8s.io/klog/v2 v2.70.1 h1:7aaoSdahviPmR+XkS7FyxlkkXs6tHISSG03RxleQAVQ= +k8s.io/klog/v2 v2.70.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42/go.mod h1:Z/45zLw8lUo4wdiUkI+v/ImEGAvu3WatcZl3lPMR4Rk= +k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 h1:MQ8BAZPZlWk3S9K4a9NCkIFQtZShWqoha7snGixVgEA= k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= -k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 h1:HNSDgDCrr/6Ly3WEGKZftiE7IY19Vz2GdbOCyI4qqhc= k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= +k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed h1:jAne/RjBTyawwAy0utX5eqigAwz/lQhTmy+Hr/Cpue4= +k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= -sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 h1:kDi4JBNAsJWfz1aEXhO8Jg87JJaPNLh5tIzYHgStQ9Y= sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2/go.mod h1:B+TnT182UBxE84DiCz4CVE26eOSDAeYCpfDnC2kdKMY= +sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k= +sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw= -sigs.k8s.io/structured-merge-diff/v4 v4.2.1 h1:bKCqE9GvQ5tiVHn5rfn1r+yao3aLQEaLzkkmAkf+A6Y= sigs.k8s.io/structured-merge-diff/v4 v4.2.1/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4= +sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE= +sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=