From d0d833ffe312ea1250672e4b164f54d93cb37243 Mon Sep 17 00:00:00 2001 From: anjan-keysight Date: Wed, 20 Apr 2022 07:49:26 +0000 Subject: [PATCH] Support for new gNMI server and version logging --- Dockerfile | 5 +---- controllers/ixiatg_controller.go | 38 +++++++++++++++++++++++--------- go.mod | 1 + go.sum | 2 ++ main.go | 11 ++++++++- version | 2 +- 6 files changed, 43 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6f89f57..389cc7e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,9 +14,6 @@ COPY main.go main.go COPY api/ api/ COPY controllers/ controllers/ -# Copy the release info json -COPY releases.json releases.json - # Build RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go @@ -25,7 +22,7 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager FROM gcr.io/distroless/static:nonroot WORKDIR / COPY --from=builder /workspace/manager . -COPY --from=builder /workspace/releases.json . +COPY version . USER 65532:65532 ENTRYPOINT ["/manager"] diff --git a/controllers/ixiatg_controller.go b/controllers/ixiatg_controller.go index 145305f..bfcc442 100644 --- a/controllers/ixiatg_controller.go +++ b/controllers/ixiatg_controller.go @@ -47,6 +47,8 @@ import ( topopb "github.com/google/kne/proto/topo" "gopkg.in/yaml.v2" + + version "github.com/hashicorp/go-version" ) const ( @@ -62,11 +64,12 @@ const ( CONFIG_MAP_NAMESPACE string = "ixiatg-op-system" DEFAULT_VERSION string = "latest" - DS_RESTAPI string = "Rest API" - DS_CONFIGMAP string = "Config Map" - CONTROLLER_SERVICE string = "ixia-c-service" - GRPC_SERVICE string = "grpc-service" - GNMI_SERVICE string = "gnmi-service" + DS_RESTAPI string = "Rest API" + DS_CONFIGMAP string = "Config Map" + CONTROLLER_SERVICE string = "ixia-c-service" + GRPC_SERVICE string = "grpc-service" + GNMI_SERVICE string = "gnmi-service" + GNMI_NEW_BASE_VERSION string = "1.7.9" ) var ( @@ -692,12 +695,13 @@ func (r *IxiaTGReconciler) containersForController(ixia *networkv1alpha1.IxiaTG, image := pubRel.Path + ":" + pubRel.Tag args := []string{"--accept-eula", "--debug"} command := []string{} - log.Infof("Adding Pod: %s, Container: %s, Image: %s", CONTROLLER_NAME, name, image) container := updateControllerContainer(corev1.Container{ Name: name, Image: image, ImagePullPolicy: "IfNotPresent", }, pubRel, args, command) + log.Infof("Adding Pod: %s, Container: %s, Image: %s, Args: %v, Cmd: %v, Env: %v, Ports: %v", + CONTROLLER_NAME, name, image, container.Args, container.Command, container.Env, container.Ports) containers = append(containers, container) } else { return nil, errors.New(fmt.Sprintf("Controller image data not found for release %s", release)) @@ -713,13 +717,14 @@ func (r *IxiaTGReconciler) containersForController(ixia *networkv1alpha1.IxiaTG, command := []string{"python3", "-m", "grpc_server", "--app-mode", "athena", "--target-host", CONTROLLER_SERVICE, "--target-port", "443", "--log-stdout", "--log-debug"} var ports []corev1.ContainerPort ports = append(ports, corev1.ContainerPort{Name: "grpc", ContainerPort: 40051, Protocol: "TCP"}) - log.Infof("Adding Pod: %s, Container: %s, Image: %s", CONTROLLER_NAME, name, image) container := updateControllerContainer(corev1.Container{ Name: name, Image: image, Ports: ports, ImagePullPolicy: "IfNotPresent", }, pubRel, args, command) + log.Infof("Adding Pod: %s, Container: %s, Image: %s, Args: %v, Cmd: %v, Env: %v, Ports: %v", + CONTROLLER_NAME, name, image, container.Args, container.Command, container.Env, container.Ports) containers = append(containers, container) } else { return nil, errors.New(fmt.Sprintf("gRPC image data not found for release %s", release)) @@ -731,17 +736,30 @@ func (r *IxiaTGReconciler) containersForController(ixia *networkv1alpha1.IxiaTG, name := "gnmi" image := pubRel.Path + ":" + pubRel.Tag - args := []string{"-http-server", "https://localhost:443", "--debug"} - command := []string{} + args := []string{} + command := []string{"python3", "-m", "otg_gnmi", "--server-port", "50051", "--app-mode", "athena", "--target-host", CONTROLLER_SERVICE, "--target-port", "443", "--insecure"} + base, err := version.NewVersion(GNMI_NEW_BASE_VERSION) + if err != nil { + log.Errorf("Failed to verify gNMI version (%s) - %v", GNMI_NEW_BASE_VERSION, err) + } else { + tag, err := version.NewVersion(pubRel.Tag) + if err != nil { + log.Errorf("Failed to verify gNMI version (%s) - %v", pubRel.Tag, err) + } else if base.LessThanOrEqual(tag) { + args = []string{"-http-server", "https://localhost:443", "--debug"} + command = []string{} + } + } var ports []corev1.ContainerPort ports = append(ports, corev1.ContainerPort{Name: "gnmi", ContainerPort: 50051, Protocol: "TCP"}) - log.Infof("Adding Pod: %s, Container: %s, Image: %s", CONTROLLER_NAME, name, image) container := updateControllerContainer(corev1.Container{ Name: name, Image: image, Ports: ports, ImagePullPolicy: "IfNotPresent", }, pubRel, args, command) + log.Infof("Adding Pod: %s, Container: %s, Image: %s, Args: %v, Cmd: %v, Env: %v, Ports: %v", + CONTROLLER_NAME, name, image, container.Args, container.Command, container.Env, container.Ports) containers = append(containers, container) } else { return nil, errors.New(fmt.Sprintf("gRPC image data not found for release %s", release)) diff --git a/go.mod b/go.mod index 2a497d9..612a4be 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/go-logr/logr v0.4.0 github.com/google/kne v0.0.0-20210520181145-85670fdcebce + github.com/hashicorp/go-version v1.4.0 // indirect github.com/onsi/ginkgo v1.14.1 github.com/onsi/gomega v1.10.2 github.com/sirupsen/logrus v1.8.0 diff --git a/go.sum b/go.sum index d0ade46..e601592 100644 --- a/go.sum +++ b/go.sum @@ -216,6 +216,8 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-version v1.4.0 h1:aAQzgqIrRKRa7w75CKpbBxYsmUoPjzVm1W59ca1L0J4= +github.com/hashicorp/go-version v1.4.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= diff --git a/main.go b/main.go index 82d627f..a6b7043 100644 --- a/main.go +++ b/main.go @@ -18,7 +18,10 @@ package main import ( "flag" + "fmt" + "io/ioutil" "os" + "strings" // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) // to ensure that exec-entrypoint and run can make use of them. @@ -97,7 +100,13 @@ func main() { os.Exit(1) } - setupLog.Info("starting manager") + if buf, err := ioutil.ReadFile("version"); err != nil { + setupLog.Error(err, "unable to read build version") + setupLog.Info("starting manager") + } else { + setupLog.Info(fmt.Sprintf("starting manager - version %s", strings.TrimSuffix(string(buf), "\n"))) + } + if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { setupLog.Error(err, "problem running manager") os.Exit(1) diff --git a/version b/version index 4ed248b..2786fad 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.0.78 +0.0.79