Skip to content

Commit 35b194c

Browse files
authored
Adding get cluster id call and bumping go version on dockerfile (#211)
1 parent 5c50561 commit 35b194c

File tree

7 files changed

+16
-30
lines changed

7 files changed

+16
-30
lines changed

build/kafka-watcher.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=$BUILDPLATFORM golang:1.22-alpine as buildenv
1+
FROM --platform=$BUILDPLATFORM golang:1.22.1-alpine as buildenv
22
RUN apk add --no-cache ca-certificates git protoc
33
RUN apk add build-base libpcap-dev
44
WORKDIR /src

build/mapper.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=$BUILDPLATFORM golang:1.22-alpine as buildenv
1+
FROM --platform=$BUILDPLATFORM golang:1.22.1-alpine as buildenv
22
RUN apk add --no-cache ca-certificates git protoc
33
RUN apk add build-base libpcap-dev
44
WORKDIR /src

build/sniffer.Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=linux/amd64 golang:1.22-alpine as buildenv
1+
FROM --platform=linux/amd64 golang:1.22.1-alpine as buildenv
22
RUN apk add --no-cache ca-certificates git protoc
33
RUN apk add build-base libpcap-dev
44
WORKDIR /src
@@ -14,7 +14,7 @@ RUN go test ./sniffer/... && echo dep > /dep
1414

1515
# We start from the base image again, only this time it's using the target arch instead of always amd64. This is done to make the build faster.
1616
# Unlike the mapper, it can't be amd64 throughout and use Go's cross-compilation, since the sniffer depends on libpcap (C library).
17-
FROM golang:1.22-alpine as builder
17+
FROM golang:1.22.1-alpine as builder
1818
COPY --from=test /dep /dep
1919
RUN apk add --no-cache ca-certificates git protoc
2020
RUN apk add build-base libpcap-dev

helm-charts

Submodule helm-charts updated 27 files

src/go.mod

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mapper/cmd/main.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"context"
55
"fmt"
66
"github.com/bombsimon/logrusr/v3"
7-
"github.com/google/uuid"
87
"github.com/labstack/echo-contrib/echoprometheus"
98
mutatingwebhookconfiguration "github.com/otterize/intents-operator/src/operator/controllers/mutating_webhook_controller"
9+
"github.com/otterize/intents-operator/src/shared/clusterutils"
1010
"github.com/otterize/intents-operator/src/shared/errors"
1111
"github.com/otterize/intents-operator/src/shared/filters"
1212
"github.com/otterize/intents-operator/src/shared/telemetries/componentinfo"
@@ -21,11 +21,8 @@ import (
2121
"github.com/otterize/network-mapper/src/mapper/pkg/pod_webhook"
2222
"github.com/otterize/network-mapper/src/shared/echologrus"
2323
"golang.org/x/sync/errgroup"
24-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2524
"k8s.io/apimachinery/pkg/runtime"
26-
"k8s.io/apimachinery/pkg/runtime/schema"
2725
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
28-
"k8s.io/client-go/metadata"
2926
"net/http"
3027
"os"
3128
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
@@ -56,7 +53,6 @@ import (
5653
ctrl "sigs.k8s.io/controller-runtime"
5754
clientconfig "sigs.k8s.io/controller-runtime/pkg/client/config"
5855
"sigs.k8s.io/controller-runtime/pkg/manager"
59-
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
6056
)
6157

6258
var (
@@ -108,8 +104,9 @@ func main() {
108104
if err != nil {
109105
logrus.Panicf("unable to set up overall controller manager: %s", err)
110106
}
107+
signalHandlerCtx := ctrl.SetupSignalHandler()
111108

112-
errgrp, errGroupCtx := errgroup.WithContext(signals.SetupSignalHandler())
109+
errgrp, errGroupCtx := errgroup.WithContext(signalHandlerCtx)
113110

114111
dnsCache := dnscache.NewDNSCache()
115112
dnsPublisher, dnsPublisherEnabled, err := dnsintentspublisher.InitWithManager(errGroupCtx, mgr, dnsCache)
@@ -139,23 +136,12 @@ func main() {
139136
return nil
140137
})
141138

142-
metadataClient, err := metadata.NewForConfig(clientconfig.GetConfigOrDie())
139+
clusterUID, err := clusterutils.GetOrCreateClusterUID(signalHandlerCtx)
143140
if err != nil {
144-
logrus.WithError(err).Panic("unable to create metadata client")
141+
logrus.WithError(err).Panic("Failed fetching cluster UID")
145142
}
146-
mapping, err := mgr.GetRESTMapper().RESTMapping(schema.GroupKind{Group: "", Kind: "Namespace"}, "v1")
147-
if err != nil {
148-
logrus.WithError(err).Panic("unable to create Kubernetes API REST mapping")
149-
}
150-
kubeSystemUID := ""
151-
kubeSystemNs, err := metadataClient.Resource(mapping.Resource).Get(context.Background(), "kube-system", metav1.GetOptions{})
152-
if err != nil || kubeSystemNs == nil {
153-
logrus.Warningf("failed getting kubesystem UID: %s", err)
154-
kubeSystemUID = fmt.Sprintf("rand-%s", uuid.New().String())
155-
} else {
156-
kubeSystemUID = string(kubeSystemNs.UID)
157-
}
158-
componentinfo.SetGlobalContextId(telemetrysender.Anonymize(kubeSystemUID))
143+
144+
componentinfo.SetGlobalContextId(telemetrysender.Anonymize(clusterUID))
159145

160146
// start API server
161147
mapperServer.GET("/healthz", func(c echo.Context) error {

0 commit comments

Comments
 (0)