Skip to content

Commit

Permalink
WIP: podresources API proxy
Browse files Browse the repository at this point in the history
WIP TBD

Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Sep 20, 2024
1 parent 43f9fec commit c78ab28
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 72 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,20 @@ build-tools: outdir _out/git-semver
extra-tools: outdir _out/nrtstress

.PHONY: build
build: build-tools
build: build-rte build-proxy

.PHONY: build-rte
build-rte: build-tools
$(COMMONENVVAR) $(BUILDENVVAR) go build \
-ldflags "-s -w -X github.com/k8stopologyawareschedwg/resource-topology-exporter/pkg/version.version=$(shell _out/git-semver)" \
-o _out/resource-topology-exporter cmd/resource-topology-exporter/main.go

.PHONY: build-proxy
build-proxy: build-tools
$(COMMONENVVAR) $(BUILDENVVAR) go build \
-ldflags "-s -w -X github.com/k8stopologyawareschedwg/resource-topology-exporter/pkg/version.version=$(shell _out/git-semver)" \
-o _out/podresources-proxy cmd/podresources-proxy/main.go

.PHONY: build-dbg
build-dbg: build-tools
$(COMMONENVVAR) $(BUILDENVVAR) go build \
Expand Down
90 changes: 90 additions & 0 deletions cmd/podresources-proxy/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2018 The Kubernetes 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 main

import (
"flag"
"os"

"k8s.io/klog/v2"

"github.com/k8stopologyawareschedwg/resource-topology-exporter/pkg/podres"
"github.com/k8stopologyawareschedwg/resource-topology-exporter/pkg/podres/proxy"
"github.com/k8stopologyawareschedwg/resource-topology-exporter/pkg/version"
)

const (
programName = "podresources-proxy"

defaultKubeletSocketPath = "/var/lib/kubelet/pod-resources/kubelet.sock"
defaultListenSocketPath = "/run/rte/podresources.sock"
)

type progArgs struct {
Verbose int
KubeletSocketPath string
ListenSocketPath string
}

func setDefaults(pa *progArgs) {
pa.KubeletSocketPath = defaultKubeletSocketPath
pa.ListenSocketPath = defaultListenSocketPath
}

func parseFlags(pa *progArgs, args ...string) error {
flags := flag.NewFlagSet(programName, flag.ExitOnError)

klog.InitFlags(flags)

flags.StringVar(&pa.KubeletSocketPath, "kubelet-socket", pa.KubeletSocketPath, "upstream kubelet podresources socket path.")
flags.StringVar(&pa.ListenSocketPath, "listen-socket", pa.ListenSocketPath, "downstream listen podresources socket path.")

return flags.Parse(args)
}

func main() {
klog.InfoS("starting", "program", programName, "version", version.Get())
defer klog.InfoS("stopped", "program", programName, "version", version.Get())

var pArgs progArgs
setDefaults(&pArgs)
err := parseFlags(&pArgs, os.Args[1:]...)

if err != nil {
klog.Fatalf("failed to parse args: %v", err)
}

klog.V(2).InfoS("connection parameters", "kubelet", pArgs.KubeletSocketPath, "listen", pArgs.ListenSocketPath)

cli, cleanup, err := podres.GetClient("unix://" + pArgs.KubeletSocketPath) // TODO: do we need smarter logic?
if err != nil {
klog.Fatalf("failed to create a podresources client: %v", err)
}

inst := proxy.New(cli, cleanup)
err = inst.Setup("unix://" + pArgs.ListenSocketPath) // TODO: do we need smarter logic?
if err != nil {
klog.Fatalf("failed to setupthe proxied podresources API: %v", err)
}

go inst.Serve()
klog.V(4).InfoS("running...")

// TODO handle signals
for {
}
}
64 changes: 33 additions & 31 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,48 @@ require (
github.com/mdomke/git-semver v1.0.0
github.com/onsi/ginkgo/v2 v2.17.1
github.com/onsi/gomega v1.32.0
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/client_golang v1.19.1
github.com/smartystreets/goconvey v1.6.4
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
go.uber.org/ratelimit v0.2.0
google.golang.org/grpc v1.58.3
k8s.io/api v0.30.5
k8s.io/apiextensions-apiserver v0.30.5
k8s.io/apimachinery v0.30.5
k8s.io/client-go v0.30.5
k8s.io/klog/v2 v2.120.1
k8s.io/kubelet v0.30.5
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
google.golang.org/grpc v1.65.0
k8s.io/api v0.31.1
k8s.io/apiextensions-apiserver v0.30.0
k8s.io/apimachinery v0.31.1
k8s.io/client-go v0.31.1
k8s.io/cri-client v0.31.1
k8s.io/klog/v2 v2.130.1
k8s.io/kubelet v0.30.0
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
sigs.k8s.io/controller-runtime v0.18.2
sigs.k8s.io/yaml v1.4.0
)

require (
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/OneOfOne/xxhash v1.2.9-0.20201014161131-8506fca4db5e // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
Expand All @@ -64,38 +66,38 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/smartystreets/assertions v1.2.0 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.18.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
howett.net/plist v1.0.0 // indirect
k8s.io/component-base v0.30.5 // indirect
k8s.io/component-base v0.31.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
Expand Down
Loading

0 comments on commit c78ab28

Please sign in to comment.