From 33ce01fda1fff7f806a17c2abc62ba2c22b9d391 Mon Sep 17 00:00:00 2001 From: zoetrope Date: Mon, 25 Nov 2024 04:34:15 +0000 Subject: [PATCH] Remove ttypdb --- .github/workflows/main.yaml | 6 - maintenance.md | 10 -- ttypdb/Dockerfile | 24 ---- ttypdb/Makefile | 24 ---- ttypdb/README.md | 20 ---- ttypdb/TAG | 1 - ttypdb/e2e.yaml | 99 ----------------- ttypdb/role.yaml | 19 ---- ttypdb/src/common/http.go | 54 --------- ttypdb/src/common/status.go | 5 - ttypdb/src/controller/main.go | 118 -------------------- ttypdb/src/controller/metrics.go | 31 ------ ttypdb/src/controller/poll.go | 179 ------------------------------ ttypdb/src/e2e/controller_test.go | 121 -------------------- ttypdb/src/e2e/kubectl_test.go | 22 ---- ttypdb/src/go.mod | 57 ---------- ttypdb/src/go.sum | 175 ----------------------------- ttypdb/src/sidecar/count.go | 59 ---------- ttypdb/src/sidecar/main.go | 84 -------------- ttypdb/src/sidecar/metrics.go | 28 ----- ttypdb/src/sidecar/status.go | 45 -------- 21 files changed, 1181 deletions(-) delete mode 100644 ttypdb/Dockerfile delete mode 100644 ttypdb/Makefile delete mode 100644 ttypdb/README.md delete mode 100644 ttypdb/TAG delete mode 100644 ttypdb/e2e.yaml delete mode 100644 ttypdb/role.yaml delete mode 100644 ttypdb/src/common/http.go delete mode 100644 ttypdb/src/common/status.go delete mode 100644 ttypdb/src/controller/main.go delete mode 100644 ttypdb/src/controller/metrics.go delete mode 100644 ttypdb/src/controller/poll.go delete mode 100644 ttypdb/src/e2e/controller_test.go delete mode 100644 ttypdb/src/e2e/kubectl_test.go delete mode 100644 ttypdb/src/go.mod delete mode 100644 ttypdb/src/go.sum delete mode 100644 ttypdb/src/sidecar/count.go delete mode 100644 ttypdb/src/sidecar/main.go delete mode 100644 ttypdb/src/sidecar/metrics.go delete mode 100644 ttypdb/src/sidecar/status.go diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 838855c79..f1160915f 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -206,12 +206,6 @@ jobs: - dir: "./trust-packages" container-image: "trust-packages" make-targets: "download-certificates" - - dir: "./ttypdb" - container-image: "ttypdb-controller" - target: "controller" - - dir: "./ttypdb" - container-image: "ttypdb-sidecar" - target: "sidecar" - dir: "./unbound" container-image: "unbound" make-targets: "check-generate" diff --git a/maintenance.md b/maintenance.md index 2e8c6ca64..b990ec53f 100644 --- a/maintenance.md +++ b/maintenance.md @@ -91,7 +91,6 @@ In case of components whose Go source code are in neco-containers, all dependent - [testhttpd](#testhttpd) - [trust-manager](#trust-manager) - [trust-packages](#trust-packages) -- [ttypdb](#ttypdb) - [unbound](#unbound) - [unbound\_exporter](#unbound_exporter) - [vault](#vault) @@ -1051,15 +1050,6 @@ TBD 2. Update `TRUST_MANAGER_VERSION` in `Dockerfile`. 3. Update `TAG` file. -## ttypdb - -![Regular Update](./regular_update.svg) - -Only the base image and module dependency should be updated. - -1. Upgrade direct dependencies listed in `go.mod`. Use `go get` or your editor's function. -2. Update `TAG` by incrementing the patch revision, e.g. 1.0.1, 1.0.2, ... - ## unbound ![Kubernetes Update](./kubernetes_update.svg) diff --git a/ttypdb/Dockerfile b/ttypdb/Dockerfile deleted file mode 100644 index d3a3b2cac..000000000 --- a/ttypdb/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -# ttypdb-xxx container - -FROM ghcr.io/cybozu/golang:1.22-jammy AS build - -COPY . /work -WORKDIR /work/src -RUN CGO_ENABLED=0 go install -ldflags="-w -s" ./... - - -FROM scratch AS sidecar -LABEL org.opencontainers.image.source="https://github.com/cybozu/neco-containers" - -COPY --from=build /go/bin/sidecar /ttypdb-sidecar -USER 10000:10000 -ENTRYPOINT ["/ttypdb-sidecar"] - - - -FROM scratch AS controller -LABEL org.opencontainers.image.source="https://github.com/cybozu/neco-containers" - -COPY --from=build /go/bin/controller /ttypdb-controller -USER 10000:10000 -ENTRYPOINT ["/ttypdb-controller"] diff --git a/ttypdb/Makefile b/ttypdb/Makefile deleted file mode 100644 index 7e4eef4f0..000000000 --- a/ttypdb/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -.PHONY: all -all: - -.PHONY: start-kind -start-kind: - kind create cluster - -.PHONY: stop-kind -stop-kind: - kind delete cluster - -.PHONY: e2e -e2e: - cd src && go test ./... -run TestE2E - -.PHONY: update-image -update-image: docker - kind load docker-image cybozu/ttypdb-sidecar:dev - kind load docker-image cybozu/ttypdb-controller:dev - -.PHONY: docker -docker: - docker build . -t cybozu/ttypdb-sidecar:dev --target sidecar - docker build . -t cybozu/ttypdb-controller:dev --target controller diff --git a/ttypdb/README.md b/ttypdb/README.md deleted file mode 100644 index ffce7df7d..000000000 --- a/ttypdb/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# ttypdb - -## ttypdb-controller - -### command-line flags - -- `-l`, `--selector`: Selector to filter Pods. Same as `-l` of `kubectl get`. default: `""` (empty string. i.e. select all Pods) -- `--interval`: Polling interval in seconds. default: `60` - -## ttypdb-sidecar - -ttypdb-sidecar counts and exposes the number of controlling terminals. - -- Pods must have `shareProcessNamespace: true` specified. -- The name of the ttypdb-sidecar container must be `ttypdb-sidecar`. -- The container must have exactly one port. - -### command-line flags - -currently, none. diff --git a/ttypdb/TAG b/ttypdb/TAG deleted file mode 100644 index 3eefcb9dd..000000000 --- a/ttypdb/TAG +++ /dev/null @@ -1 +0,0 @@ -1.0.0 diff --git a/ttypdb/e2e.yaml b/ttypdb/e2e.yaml deleted file mode 100644 index 6393921fb..000000000 --- a/ttypdb/e2e.yaml +++ /dev/null @@ -1,99 +0,0 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - name: ttypdb-controller ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: RoleBinding -metadata: - name: ttypdb-controller -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: Role - name: ttypdb-controller -subjects: -- kind: ServiceAccount - name: ttypdb-controller ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: ttypdb-controller -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/name: ttypdb-controller - template: - metadata: - labels: - app.kubernetes.io/name: ttypdb-controller - spec: - serviceAccountName: ttypdb-controller - containers: - - name: monitor - image: cybozu/ttypdb-controller:dev - imagePullPolicy: Never - args: - - "-lfoo=bar" - - "--interval=5" ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: teststs -spec: - replicas: 2 - selector: - matchLabels: - name: teststs - serviceName: teststs - template: - metadata: - labels: - name: teststs - foo: bar - hoge: fuga - spec: - containers: - - name: main - image: ghcr.io/cybozu/ubuntu:22.04 - imagePullPolicy: IfNotPresent - command: [ "sleep", "infinity" ] - - name: ttypdb-sidecar - image: cybozu/ttypdb-sidecar:dev - imagePullPolicy: Never - ports: - - name: sidecar - containerPort: 8080 - shareProcessNamespace: true ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: teststs2 -spec: - replicas: 1 - selector: - matchLabels: - name: teststs2 - serviceName: teststs2 - template: - metadata: - labels: - name: teststs2 - foo: baz - hoge: piyo - spec: - containers: - - name: main - image: ghcr.io/cybozu/ubuntu:22.04 - imagePullPolicy: IfNotPresent - command: [ "sleep", "infinity" ] - - name: ttypdb-sidecar - image: cybozu/ttypdb-sidecar:dev - imagePullPolicy: Never - ports: - - name: sidecar - containerPort: 8080 - shareProcessNamespace: true diff --git a/ttypdb/role.yaml b/ttypdb/role.yaml deleted file mode 100644 index 88d6c8960..000000000 --- a/ttypdb/role.yaml +++ /dev/null @@ -1,19 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: ttypdb-controller -rules: -- apiGroups: - - "" - resources: - - pods - verbs: - - list -- apiGroups: - - "policy" - resources: - - poddisruptionbudgets - verbs: - - create - - get - - delete diff --git a/ttypdb/src/common/http.go b/ttypdb/src/common/http.go deleted file mode 100644 index 3bb7d1e2e..000000000 --- a/ttypdb/src/common/http.go +++ /dev/null @@ -1,54 +0,0 @@ -package common - -import ( - "net/http" - "time" - - "go.uber.org/zap" -) - -type proxyHTTPHandler struct { - http.Handler - logger *zap.Logger -} - -type proxyHTTPResponseWriter struct { - http.ResponseWriter - statusCode int -} - -func NewProxyHTTPHandler(orig http.Handler, logger *zap.Logger) http.Handler { - return &proxyHTTPHandler{ - Handler: orig, - logger: logger, - } -} - -func (h *proxyHTTPHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { - start := time.Now() - - prw := &proxyHTTPResponseWriter{ - ResponseWriter: rw, - } - h.Handler.ServeHTTP(prw, req) - - if prw.statusCode == 0 { - prw.statusCode = http.StatusOK - } - - logfn := h.logger.Info - if prw.statusCode >= 500 { - logfn = h.logger.Error - } else if prw.statusCode >= 400 { - logfn = h.logger.Warn - } - logfn("http access", - zap.String("path", req.URL.Path), - zap.Int("status", prw.statusCode), - zap.Float64("duration", time.Since(start).Seconds())) -} - -func (rw *proxyHTTPResponseWriter) WriteHeader(statusCode int) { - rw.statusCode = statusCode - rw.ResponseWriter.WriteHeader(statusCode) -} diff --git a/ttypdb/src/common/status.go b/ttypdb/src/common/status.go deleted file mode 100644 index 4e4abd78a..000000000 --- a/ttypdb/src/common/status.go +++ /dev/null @@ -1,5 +0,0 @@ -package common - -type Status struct { - TTYs int `json:"ttys"` -} diff --git a/ttypdb/src/controller/main.go b/ttypdb/src/controller/main.go deleted file mode 100644 index da692dabf..000000000 --- a/ttypdb/src/controller/main.go +++ /dev/null @@ -1,118 +0,0 @@ -package main - -import ( - "context" - "fmt" - "net/http" - "os" - "os/signal" - "sync" - "syscall" - "ttypdb/common" - - "github.com/spf13/pflag" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/rest" - - "github.com/prometheus/client_golang/prometheus/promhttp" - "go.uber.org/zap" -) - -const httpServerPort = 8080 -const defaultPollIntervalSeconds = 60 - -var currentNamespace string - -var flagSelector = pflag.StringP("selector", "l", "", "Selector to filter Pods") -var flagPollIntervalSeconds = pflag.Int("interval", defaultPollIntervalSeconds, "Polling interval in seconds") - -func newZapLogger() *zap.Logger { - logger, err := zap.NewProduction() - if err != nil { - panic(err) - } - return logger -} - -func main() { - os.Exit(run()) -} - -func run() int { - logger := newZapLogger() - defer logger.Sync() - - pflag.Parse() - - logger.Info("starting ttypdb-sidecar...") - - //initMetrics(logger) - - config, err := rest.InClusterConfig() - if err != nil { - panic(err) - } - clientset, err := kubernetes.NewForConfig(config) - if err != nil { - panic(err) - } - - ns, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace") - if err != nil { - panic(err) - } - currentNamespace = string(ns) - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - wg := sync.WaitGroup{} - - signalCh := make(chan os.Signal, 1) - signal.Notify(signalCh, syscall.SIGTERM, syscall.SIGINT) - wg.Add(1) - go func() { - defer wg.Done() - defer cancel() - select { - case signal := <-signalCh: - logger.Info("caught signal", zap.String("signal", signal.String())) - case <-ctx.Done(): - } - }() - - mux := http.NewServeMux() - mux.HandleFunc("/readyz", handleReadyz) - mux.Handle("/metrics", promhttp.Handler()) - server := http.Server{ - Addr: fmt.Sprintf(":%d", httpServerPort), - Handler: common.NewProxyHTTPHandler(mux, logger), - } - wg.Add(1) - go func() { - defer wg.Done() - defer cancel() - go func() { - <-ctx.Done() - server.Shutdown(context.Background()) - }() - err := server.ListenAndServe() - if err != http.ErrServerClosed { - logger.Error("failed to start HTTP server", zap.Error(err)) - } - }() - - wg.Add(1) - go func() { - defer wg.Done() - defer cancel() - pollPods(ctx, logger, clientset) - }() - - wg.Wait() - logger.Info("termination completed") - return 0 -} - -func handleReadyz(http.ResponseWriter, *http.Request) { - // Nothing to do for now -} diff --git a/ttypdb/src/controller/metrics.go b/ttypdb/src/controller/metrics.go deleted file mode 100644 index 3abf702eb..000000000 --- a/ttypdb/src/controller/metrics.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "github.com/prometheus/client_golang/prometheus" -) - -const metricsNamespace = "ttypdb_controller" - -var metricsPollingSkipsCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: metricsNamespace, - Name: "polling_skips_total", - Help: "Number of polling skips", - }, -) - -var metricsPollingDurationSecondsHistogram = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: metricsNamespace, - Name: "polling_duration_seconds", - Help: "Polling duration took", - Buckets: []float64{0.001, 0.002, 0.004, 0.008, 0.012, 0.016, 0.024, 0.032, 0.064, 0.096, 0.128, 0.256, 0.512, 1.024}, - }, -) - -func init() { - prometheus.MustRegister( - metricsPollingSkipsCounter, - metricsPollingDurationSecondsHistogram, - ) -} diff --git a/ttypdb/src/controller/poll.go b/ttypdb/src/controller/poll.go deleted file mode 100644 index 8c312a710..000000000 --- a/ttypdb/src/controller/poll.go +++ /dev/null @@ -1,179 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "io" - "net/http" - "sync" - "time" - "ttypdb/common" - - "go.uber.org/zap" - corev1 "k8s.io/api/core/v1" - policyv1 "k8s.io/api/policy/v1" - k8serrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/client-go/kubernetes" -) - -func pollPods(ctx context.Context, logger *zap.Logger, clientset *kubernetes.Clientset) { - ticker := time.NewTicker(time.Second * time.Duration(*flagPollIntervalSeconds)) - defer ticker.Stop() - - m := sync.Mutex{} - - for { - select { - case <-ctx.Done(): - m.Lock() // wait for doPollPods completion - return - case <-ticker.C: - if m.TryLock() { - go func() { - defer m.Unlock() - doPollPods(ctx, logger, clientset) - }() - } else { - metricsPollingSkipsCounter.Inc() - logger.Warn(fmt.Sprintf("The previous polling takes more than %d seconds. Skip polling this time.", *flagPollIntervalSeconds)) - } - } - } -} - -func doPollPods(ctx context.Context, logger *zap.Logger, clientset *kubernetes.Clientset) { - logger.Info("polling start") - startTime := time.Now() - defer func() { - duration := time.Since(startTime) - metricsPollingDurationSecondsHistogram.Observe(duration.Seconds()) - logger.Info("polling completed", zap.Duration("duration", duration.Round(time.Millisecond))) - }() - - podList, err := clientset.CoreV1().Pods(currentNamespace).List(ctx, metav1.ListOptions{ - LabelSelector: *flagSelector, - }) - if err != nil { - logger.Error("failed to list Pods", zap.Error(err)) - return - } - - logger.Info("listed Pods", zap.Int("count", len(podList.Items))) - for _, pod := range podList.Items { - checkPod(ctx, logger.With(zap.String("namespace", pod.Namespace), zap.String("pod", pod.Name)), clientset, &pod) - } -} - -func checkPod(ctx context.Context, logger *zap.Logger, clientset *kubernetes.Clientset, pod *corev1.Pod) { - if pod.DeletionTimestamp != nil { - logger.Debug("the Pod is about to be deleted. skipping.") - return - } - - podIP := pod.Status.PodIP - - var container *corev1.Container - for _, c := range pod.Spec.Containers { - if c.Name == "ttypdb-sidecar" { - container = &c - break - } - } - if container == nil { - logger.Error("failed to find sidecar container") - return - } - if len(container.Ports) < 1 { - logger.Error("failed to get sidecar container port") - return - } - - resp, err := http.Get(fmt.Sprintf("http://%s:%d/status", podIP, container.Ports[0].ContainerPort)) - if err != nil { - logger.Error("failed to get status", zap.Error(err)) - return - } - defer resp.Body.Close() - - status := common.Status{} - statusBytes, err := io.ReadAll(resp.Body) - if err != nil { - logger.Error("failed to get status", zap.Error(err)) - return - } - err = json.Unmarshal(statusBytes, &status) - if err != nil { - logger.Error("failed to unmarshal status", zap.Error(err)) - return - } - if status.TTYs < 0 { - logger.Error("broken status") - return - } - - pdbInterface := clientset.PolicyV1().PodDisruptionBudgets(pod.Namespace) - foundPdb := false - _, err = pdbInterface.Get(ctx, pod.Name, metav1.GetOptions{}) - if err != nil { - var k8serr *k8serrors.StatusError - if !errors.As(err, &k8serr) || k8serr.Status().Reason != metav1.StatusReasonNotFound { - logger.Error("failed to check PDB", zap.Error(err)) - return - } - } else { - foundPdb = true - } - - if status.TTYs == 0 { - // no controlling terminals are observed. delete PDB. - if !foundPdb { - logger.Debug("PDB does not exist") - return - } - - err := pdbInterface.Delete(ctx, pod.Name, metav1.DeleteOptions{}) - if err != nil { - logger.Error("failed to delete PDB", zap.Error(err)) - } else { - logger.Info("deleted PDB") - } - } else { - // some controlling terminals are observed. create PDB. - if foundPdb { - logger.Debug("PDB already exists") - return - } - - zeroIntstr := intstr.FromInt(0) - pdb := &policyv1.PodDisruptionBudget{ - ObjectMeta: metav1.ObjectMeta{ - Name: pod.Name, - Namespace: pod.Namespace, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "v1", - Kind: "Pod", - Name: pod.GetName(), - UID: pod.GetUID(), - }, - }, - }, - Spec: policyv1.PodDisruptionBudgetSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: pod.Labels, - }, - MaxUnavailable: &zeroIntstr, - }, - } - _, err = pdbInterface.Create(ctx, pdb, metav1.CreateOptions{}) - if err != nil { - logger.Error("failed to create PDB", zap.Error(err)) - } else { - logger.Info("created PDB") - } - } -} diff --git a/ttypdb/src/e2e/controller_test.go b/ttypdb/src/e2e/controller_test.go deleted file mode 100644 index 96f1f694d..000000000 --- a/ttypdb/src/e2e/controller_test.go +++ /dev/null @@ -1,121 +0,0 @@ -package e2e - -import ( - "encoding/json" - "fmt" - "os" - "testing" - "time" - - policyv1 "k8s.io/api/policy/v1" -) - -const configuredPollingIntervalSeconds = 5 -const testIntervalSeconds = configuredPollingIntervalSeconds + 2 -const testInterval = time.Second * time.Duration(testIntervalSeconds) - -func TestE2E(t *testing.T) { - // this test is intended to be run from a terminal by hand. - // If you want to run from CI environment, PTY should be used. - tty, err := os.Open("/dev/tty") - if err != nil { - t.Fatal("cannot open /dev/tty", err) - } - defer tty.Close() - - // prepare - - _, stderr, err := kubectl("apply", "-f", "../../role.yaml") - if err != nil { - t.Fatal("failed to apply role.yaml", err, string(stderr)) - } - _, stderr, err = kubectl("apply", "-f", "../../e2e.yaml") - if err != nil { - t.Fatal("failed to apply e2e.yaml", err, string(stderr)) - } - - // PDBs should not exist in initial state - - time.Sleep(testInterval) - - stdout, stderr, err := kubectl("get", "pdb", "--ignore-not-found", "-ojson") - if err != nil { - t.Fatal("failed to get pdb list", err, string(stderr)) - } - if len(stdout) != 0 { - t.Error("unexpected pdb exists", string(stdout)) - } - - // a PDB should be created for teststs-0 because it is selected by `-l` option of the controller - - go func() { - _, stderr, err := kubectlWithReaderStdin(tty, "exec", "teststs-0", "-it", "--", "sleep", fmt.Sprintf("%d", testIntervalSeconds)) - if err != nil { - t.Error("failed to login to pod", err, string(stderr)) - } - }() - - time.Sleep(testInterval) - - fmt.Println("PDB should be created for teststs-0") - stdout, stderr, err = kubectl("get", "pdb", "--ignore-not-found", "-ojson") - if err != nil { - t.Fatal("failed to get pdb list", err, string(stderr)) - } - if len(stdout) == 0 { - t.Error("expected pdb does not exist") - } - pdbList := policyv1.PodDisruptionBudgetList{} - err = json.Unmarshal(stdout, &pdbList) - if err != nil { - t.Fatal("failed to unmarshal json", err) - } - if len(pdbList.Items) != 1 { - t.Error("expected pdb does not exist", pdbList.Items) - } - if pdbList.Items[0].Name != "teststs-0" { - t.Error("expected pdb does not exist", pdbList.Items) - } - if pdbList.Items[0].Spec.Selector.MatchLabels["statefulset.kubernetes.io/pod-name"] != "teststs-0" { - t.Error("expected pdb does not exist", pdbList.Items) - } - - // the PDB should be deleted after the logout from the Pod - - time.Sleep(testInterval) - - fmt.Println("PDB should be deleted") - stdout, stderr, err = kubectl("get", "pdb", "--ignore-not-found", "-ojson") - if err != nil { - t.Fatal("failed to get pdb list", err, string(stderr)) - } - if len(stdout) != 0 { - t.Error("unexpected pdb exists", string(stdout)) - } - - // a PDB should not be created for teststs2-0 because it is not selected by `-l` option of the controller - - go func() { - _, stderr, err := kubectlWithReaderStdin(tty, "exec", "teststs2-0", "-it", "--", "sleep", fmt.Sprintf("%d", testIntervalSeconds)) - if err != nil { - t.Error("failed to login to pod", err, string(stderr)) - } - }() - - time.Sleep(testInterval) - - stdout, stderr, err = kubectl("get", "pdb", "--ignore-not-found", "-ojson") - if err != nil { - t.Fatal("failed to get pdb list", err, string(stderr)) - } - if len(stdout) != 0 { - t.Error("unexpected pdb exists", string(stdout)) - } - - // cleanup - - _, stderr, err = kubectl("delete", "-f", "../../e2e.yaml") - if err != nil { - t.Fatal(err, string(stderr)) - } -} diff --git a/ttypdb/src/e2e/kubectl_test.go b/ttypdb/src/e2e/kubectl_test.go deleted file mode 100644 index 34117fa1c..000000000 --- a/ttypdb/src/e2e/kubectl_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package e2e - -import ( - "bytes" - "io" - "os/exec" -) - -func kubectl(args ...string) ([]byte, []byte, error) { - return kubectlWithReaderStdin(nil, args...) -} - -func kubectlWithReaderStdin(stdin io.Reader, args ...string) ([]byte, []byte, error) { - stdoutBuffer := new(bytes.Buffer) - stderrBuffer := new(bytes.Buffer) - cmd := exec.Command("kubectl", args...) - cmd.Stdin = stdin - cmd.Stdout = stdoutBuffer - cmd.Stderr = stderrBuffer - err := cmd.Run() - return stdoutBuffer.Bytes(), stderrBuffer.Bytes(), err -} diff --git a/ttypdb/src/go.mod b/ttypdb/src/go.mod deleted file mode 100644 index 240193b48..000000000 --- a/ttypdb/src/go.mod +++ /dev/null @@ -1,57 +0,0 @@ -module ttypdb - -go 1.22.1 - -require ( - github.com/prometheus/client_golang v1.19.0 - github.com/spf13/pflag v1.0.5 - go.uber.org/zap v1.27.0 - k8s.io/api v0.29.3 - k8s.io/apimachinery v0.29.3 - k8s.io/client-go v0.29.3 -) - -require ( - github.com/beorn7/perks v1.0.1 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/emicklei/go-restful/v3 v3.12.0 // indirect - github.com/go-logr/logr v1.4.1 // indirect - github.com/go-openapi/jsonpointer v0.21.0 // indirect - github.com/go-openapi/jsonreference v0.21.0 // indirect - github.com/go-openapi/swag v0.23.0 // 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/uuid v1.6.0 // indirect - github.com/josharian/intern v1.0.0 // indirect - github.com/json-iterator/go v1.1.12 // indirect - github.com/mailru/easyjson v0.7.7 // 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/onsi/ginkgo/v2 v2.17.0 // indirect - github.com/onsi/gomega v1.32.0 // indirect - github.com/prometheus/client_model v0.6.0 // indirect - github.com/prometheus/common v0.51.0 // indirect - github.com/prometheus/procfs v0.13.0 // indirect - go.uber.org/multierr v1.11.0 // indirect - golang.org/x/net v0.23.0 // indirect - golang.org/x/oauth2 v0.18.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 - golang.org/x/time v0.5.0 // indirect - google.golang.org/appengine v1.6.8 // indirect - google.golang.org/protobuf v1.33.0 // 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 - k8s.io/klog/v2 v2.120.1 // indirect - k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect - k8s.io/utils v0.0.0-20240310230437-4693a0247e57 // indirect - sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect - sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect - sigs.k8s.io/yaml v1.4.0 // indirect -) diff --git a/ttypdb/src/go.sum b/ttypdb/src/go.sum deleted file mode 100644 index 58d53fd86..000000000 --- a/ttypdb/src/go.sum +++ /dev/null @@ -1,175 +0,0 @@ -github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= -github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= -github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/emicklei/go-restful/v3 v3.12.0 h1:y2DdzBAURM29NFF94q6RaY4vjIH1rtwDapwQtU84iWk= -github.com/emicklei/go-restful/v3 v3.12.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= -github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= -github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= -github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ= -github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4= -github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= -github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= -github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= -github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= -github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= -github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= -github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= -github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= -github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= -github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= -github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/onsi/ginkgo/v2 v2.17.0 h1:kdnunFXpBjbzN56hcJHrXZ8M+LOkenKA7NnBzTNigTI= -github.com/onsi/ginkgo/v2 v2.17.0/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs= -github.com/onsi/gomega v1.32.0 h1:JRYU78fJ1LPxlckP6Txi/EYqJvjtMrDC04/MM5XRHPk= -github.com/onsi/gomega v1.32.0/go.mod h1:a4x4gW6Pz2yK1MAmvluYme5lvYTn61afQ2ETw/8n4Lg= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU= -github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= -github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos= -github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8= -github.com/prometheus/common v0.51.0 h1:vT5R9NAlW4V6k8Wruk7ikrHaHRsrPbduM/cKTOdQM/k= -github.com/prometheus/common v0.51.0/go.mod h1:wHFBCEVWVmHMUpg7pYcOm2QUR/ocQdYSJVQJKnHc3xQ= -github.com/prometheus/procfs v0.13.0 h1:GqzLlQyfsPbaEHaQkO7tbDlriv/4o5Hudv6OXHGKX7o= -github.com/prometheus/procfs v0.13.0/go.mod h1:cd4PFCR54QLnGKPaKGA6l+cfuNXtht43ZKY6tow0Y1g= -github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= -go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= -go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= -go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= -golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= -golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI= -golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= -golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= -golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= -golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= -google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= -gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/api v0.29.3 h1:2ORfZ7+bGC3YJqGpV0KSDDEVf8hdGQ6A03/50vj8pmw= -k8s.io/api v0.29.3/go.mod h1:y2yg2NTyHUUkIoTC+phinTnEa3KFM6RZ3szxt014a80= -k8s.io/apimachinery v0.29.3 h1:2tbx+5L7RNvqJjn7RIuIKu9XTsIZ9Z5wX2G22XAa5EU= -k8s.io/apimachinery v0.29.3/go.mod h1:hx/S4V2PNW4OMg3WizRrHutyB5la0iCUbZym+W0EQIU= -k8s.io/client-go v0.29.3 h1:R/zaZbEAxqComZ9FHeQwOh3Y1ZUs7FaHKZdQtIc2WZg= -k8s.io/client-go v0.29.3/go.mod h1:tkDisCvgPfiRpxGnOORfkljmS+UrW+WtXAy2fTvXJB0= -k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw= -k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= -k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag= -k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98= -k8s.io/utils v0.0.0-20240310230437-4693a0247e57 h1:gbqbevonBh57eILzModw6mrkbwM0gQBEuevE/AaBsHY= -k8s.io/utils v0.0.0-20240310230437-4693a0247e57/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= -sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= -sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4= -sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08= -sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= -sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/ttypdb/src/sidecar/count.go b/ttypdb/src/sidecar/count.go deleted file mode 100644 index a5994c738..000000000 --- a/ttypdb/src/sidecar/count.go +++ /dev/null @@ -1,59 +0,0 @@ -package main - -import ( - "errors" - "os" - "path/filepath" - "strings" -) - -var errProcStat = errors.New("broken process stat") - -// ttyCount returns the number of controlling terminals observed. -// NOTE: This implementation is for Linux. -func ttyCount() (int, error) { - dirs, err := os.ReadDir("/proc") - if err != nil { - return 0, err - } - - ttys := map[string]bool{} - for _, d := range dirs { - err := func() error { - name := d.Name() - for _, ch := range name { - if ch < '0' || ch > '9' { - return nil - } - } - - statBytes, err := os.ReadFile(filepath.Join("/proc", name, "stat")) - if err != nil { - return err - } - - // The 6th (0-origin) field is controlling tty device number. - // If it is "0", the process is not controlled. - stat := string(statBytes) - idx := strings.LastIndexByte(stat, ')') - if idx == -1 { - return errProcStat - } - stat = stat[idx+2:] // two fields are skipped - fields := strings.SplitN(stat, " ", 6) - if len(fields) <= 4 { - return errProcStat - } - ttyNumber := fields[4] - if ttyNumber != "0" { - ttys[ttyNumber] = true - } - return nil - }() - if err != nil { - return 0, err - } - } - - return len(ttys), nil -} diff --git a/ttypdb/src/sidecar/main.go b/ttypdb/src/sidecar/main.go deleted file mode 100644 index 05c5bd7d6..000000000 --- a/ttypdb/src/sidecar/main.go +++ /dev/null @@ -1,84 +0,0 @@ -package main - -import ( - "context" - "fmt" - "net/http" - "os" - "os/signal" - "sync" - "syscall" - "ttypdb/common" - - "github.com/prometheus/client_golang/prometheus/promhttp" - "go.uber.org/zap" -) - -const httpServerPort = 8080 - -func newZapLogger() *zap.Logger { - logger, err := zap.NewProduction() - if err != nil { - panic(err) - } - return logger -} - -func main() { - os.Exit(run()) -} - -func run() int { - logger := newZapLogger() - defer logger.Sync() - logger.Info("starting ttypdb-sidecar...") - - initMetrics(logger) - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - wg := sync.WaitGroup{} - - signalCh := make(chan os.Signal, 1) - signal.Notify(signalCh, syscall.SIGTERM, syscall.SIGINT) - wg.Add(1) - go func() { - defer wg.Done() - defer cancel() - select { - case signal := <-signalCh: - logger.Info("caught signal", zap.String("signal", signal.String())) - case <-ctx.Done(): - } - }() - - mux := http.NewServeMux() - mux.HandleFunc("/readyz", handleReadyz) - mux.Handle("/metrics", promhttp.Handler()) - mux.Handle("/status", NewStatusHandler(logger)) - server := http.Server{ - Addr: fmt.Sprintf(":%d", httpServerPort), - Handler: common.NewProxyHTTPHandler(mux, logger), - } - wg.Add(1) - go func() { - defer wg.Done() - defer cancel() - go func() { - <-ctx.Done() - server.Shutdown(context.Background()) - }() - err := server.ListenAndServe() - if err != http.ErrServerClosed { - logger.Error("failed to start HTTP server", zap.Error(err)) - } - }() - - wg.Wait() - logger.Info("termination completed") - return 0 -} - -func handleReadyz(http.ResponseWriter, *http.Request) { - // Nothing to do for now -} diff --git a/ttypdb/src/sidecar/metrics.go b/ttypdb/src/sidecar/metrics.go deleted file mode 100644 index 346966423..000000000 --- a/ttypdb/src/sidecar/metrics.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "math" - - "github.com/prometheus/client_golang/prometheus" - "go.uber.org/zap" -) - -const metricsNamespace = "ttypdb_sidecar" - -func initMetrics(logger *zap.Logger) { - prometheus.MustRegister(prometheus.NewGaugeFunc( - prometheus.GaugeOpts{ - Namespace: metricsNamespace, - Name: "ttys", - Help: "Number of controlling terminals observed", - }, - func() float64 { - ttys, err := ttyCount() - if err != nil { - logger.Error("failed to count ttys", zap.Error(err)) - return math.NaN() - } - return float64(ttys) - }, - )) -} diff --git a/ttypdb/src/sidecar/status.go b/ttypdb/src/sidecar/status.go deleted file mode 100644 index b7ae1217a..000000000 --- a/ttypdb/src/sidecar/status.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "encoding/json" - "net/http" - "ttypdb/common" - - "go.uber.org/zap" -) - -type StatusHandler struct { - logger *zap.Logger -} - -func NewStatusHandler(logger *zap.Logger) http.Handler { - return &StatusHandler{ - logger: logger, - } -} - -func writeError(w http.ResponseWriter, err error) { - w.WriteHeader(http.StatusInternalServerError) - w.Header().Add("Content-Type", "text/plain") - w.Write([]byte(err.Error())) -} - -func (h *StatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - num, err := ttyCount() - if err != nil { - h.logger.Error("failed to count ttys", zap.Error(err)) - writeError(w, err) - return - } - status := common.Status{ - TTYs: num, - } - out, err := json.Marshal(&status) - if err != nil { - h.logger.Error("failed to marshal", zap.Error(err)) - writeError(w, err) - return - } - w.Header().Add("Content-Type", "application/json") - w.Write(out) -}