Skip to content

Commit

Permalink
Support for new gNMI server and version logging
Browse files Browse the repository at this point in the history
  • Loading branch information
anjan-keysight committed Apr 20, 2022
1 parent 60b1570 commit d0d833f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 16 deletions.
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"]
38 changes: 28 additions & 10 deletions controllers/ixiatg_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import (
topopb "github.com/google/kne/proto/topo"

"gopkg.in/yaml.v2"

version "github.com/hashicorp/go-version"
)

const (
Expand All @@ -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 (
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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))
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.78
0.0.79

0 comments on commit d0d833f

Please sign in to comment.