Skip to content

Commit

Permalink
Added support for teems data (#2480)
Browse files Browse the repository at this point in the history
Signed-off-by: Vivek Lohiya <vklohiya@live.com>
  • Loading branch information
vklohiya authored Jul 6, 2022
1 parent 8e63211 commit c85a77d
Show file tree
Hide file tree
Showing 39 changed files with 2,136 additions and 68 deletions.
96 changes: 41 additions & 55 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,16 @@ all: local-build

test: local-go-test

prod: prod-build
prod: fmt prod-build

verify: fmt vet

docs: _docs


godep-restore: check-gopath
godep restore
rm -rf vendor Godeps

godep-save: check-gopath
godep save ./...

clean:
rm -rf _docker_workspace
rm -rf _build
rm -rf docs/_build
rm -f *_attributions.json
rm -f *_attributions.csv
rm -f docs/_static/ATTRIBUTIONS.md
docker volume rm -f workspace_vol
@echo "Did not clean local go workspace"

info:
Expand Down Expand Up @@ -84,24 +73,28 @@ pre-build:
git describe --all --long --always

prod-build: pre-build
@echo "Building with minimal instrumentation..."
BASE_OS=$(BASE_OS) $(CURDIR)/build-tools/build-devel-image.sh
RUN_TESTS=1 BASE_OS=$(BASE_OS) $(CURDIR)/build-tools/build-release-artifacts.sh
BASE_OS=$(BASE_OS) $(CURDIR)/build-tools/build-release-images.sh
@echo "Building with running tests..."

docker build --build-arg RUN_TESTS=1 --build-arg BUILD_VERSION=$(BUILD_VERSION) --build-arg BUILD_INFO=$(BUILD_INFO) -t k8s-bigip-ctlr:latest -f build-tools/Dockerfile.$(BASE_OS) .

prod-quick: prod-build-quick

prod-build-quick: pre-build
@echo "Building with running tests..."
BASE_OS=$(BASE_OS) $(CURDIR)/build-tools/build-devel-image.sh
RUN_TESTS=0 BASE_OS=$(BASE_OS) $(CURDIR)/build-tools/build-release-artifacts.sh
BASE_OS=$(BASE_OS) $(CURDIR)/build-tools/build-release-images.sh
@echo "Quick build without running tests..."
docker build --build-arg RUN_TESTS=0 --build-arg BUILD_VERSION=$(BUILD_VERSION) --build-arg BUILD_INFO=$(BUILD_INFO) -t k8s-bigip-ctlr:latest -f build-tools/Dockerfile.$(BASE_OS) .

dev-license: pre-build
@echo "Running with tests and licenses generated will be in all_attributions.txt..."
docker build -t cis-attributions:latest -f build-tools/Dockerfile.attribution .
$(eval id := $(shell docker create cis-attributions:latest))
docker cp $(id):/opt/all_attributions.txt ./
docker rm -v $(id)
docker rmi -f cis-attributions:latest

debug: pre-build
@echo "Building with debug support..."
BASE_OS=$(BASE_OS) $(CURDIR)/build-tools/build-devel-image.sh
DEBUG=0 RUN_TESTS=0 BASE_OS=$(BASE_OS) $(CURDIR)/build-tools/build-release-artifacts.sh
DEBUG=0 BASE_OS=$(BASE_OS) $(CURDIR)/build-tools/build-release-images.sh
docker build --build-arg RUN_TESTS=0 --build-arg BUILD_VERSION=$(BUILD_VERSION) --build-arg BUILD_INFO=$(BUILD_INFO) -t k8s-bigip-ctlr-dbg:latest -f build-tools/Dockerfile.debug .


fmt:
@echo "Enforcing code formatting using 'go fmt'..."
Expand All @@ -112,7 +105,7 @@ vet:
$(CURDIR)/build-tools/vet.sh

devel-image:
BASE_OS=$(BASE_OS) ./build-tools/build-devel-image.sh
docker build --build-arg RUN_TESTS=0 --build-arg BUILD_VERSION=$(BUILD_VERSION) --build-arg BUILD_INFO=$(BUILD_INFO) -t k8s-bigip-ctlr-devel:latest -f build-tools/Dockerfile.(BASE_OS) .

# Enable certain funtionalities only on a developer build
dev-patch:
Expand All @@ -125,45 +118,38 @@ reset-dev-patch:
# Build devloper image
dev: dev-patch prod-quick reset-dev-patch

#
# Docs
#
doc-preview:
rm -rf docs/_build
DOCKER_RUN_ARGS="-p 127.0.0.1:8000:8000" \
./build-tools/docker-docs.sh make -C docs preview

_docs: docs/_static/ATTRIBUTIONS.md always-build
_docs: always-build
./build-tools/docker-docs.sh ./build-tools/make-docs.sh

docker-test:
rm -rf docs/_build
./build-tools/docker-docs.sh ./build-tools/make-docs.sh

# one-time html build using a docker container
.PHONY: docker-html
docker-html:
rm -rf docs/_build
./build-tools/docker-docs.sh make -C docs/ html

#
# Attributions Generation
#
golang_attributions.json: Godeps/Godeps.json
./build-tools/attributions-generator.sh \
/usr/local/bin/golang-backend.py --project-path=$(CURDIR)

flatfile_attributions.json: .f5license
./build-tools/attributions-generator.sh \
/usr/local/bin/flatfile-backend.py --project-path=$(CURDIR)

pip_attributions.json: always-build
./build-tools/attributions-generator.sh \
/usr/local/bin/pip-backend.py \
--requirements=requirements.txt \
--project-path=$(CURDIR) \

docs/_static/ATTRIBUTIONS.md: flatfile_attributions.json golang_attributions.json pip_attributions.json
./build-tools/attributions-generator.sh \
node /frontEnd/frontEnd.js --pd $(CURDIR) $(LIC_FLAG)
mv ATTRIBUTIONS.md $@
docker-tag:
ifdef tag
docker tag k8s-bigip-ctlr:latest $(tag)
docker push $(tag)
else
@echo "Define a tag to push. Eg: make docker-tag tag=username/k8s-bigip-ctlr:dev"
endif

docker-devel-tag:
docker push k8s-bigip-ctlr-devel:latest

docker-dbg-tag:
ifdef tag
docker tag k8s-bigip-ctlr-dbg:latest $(tag)
docker push $(tag)
else
@echo "Define a tag to push. Eg: make docker-tag tag=username/k8s-bigip-ctlr:dev"
endif

crd-code-gen:
docker run --name crdcodegen -v $(PWD):/go/src/github.com/F5Networks/k8s-bigip-ctlr quay.io/f5networks/ciscrdcodegen:latest
docker rm crdcodegen
113 changes: 111 additions & 2 deletions cmd/k8s-bigip-ctlr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"encoding/json"
"fmt"
"github.com/F5Networks/k8s-bigip-ctlr/pkg/teem"
"io/ioutil"
"net/http"
"net/url"
Expand Down Expand Up @@ -68,6 +69,25 @@ type bigIPSection struct {
BigIPPartitions []string `json:"partitions,omitempty"`
}

// OCP4 Version for TEEM
type (
Ocp4Version struct {
Status ClusterVersionStatus `json:"status"`
}
ClusterVersionStatus struct {
History []UpdateHistory `json:"history,omitempty"`
}
UpdateHistory struct {
Version string `json:"version"`
}
)

const (
versionPathOpenshiftv3 = "/version/openshift"
versionPathOpenshiftv4 = "/apis/config.openshift.io/v1/clusterversions/version"
versionPathk8s = "/version"
)

var (
// To be set by build
version string
Expand All @@ -87,6 +107,7 @@ var (
nodePollInterval *int
printVersion *bool
httpAddress *string
disableTeems *bool

namespaces *[]string
useNodeInternal *bool
Expand Down Expand Up @@ -138,6 +159,7 @@ var (
isNodePort bool
watchAllNamespaces bool
vxlanName string
kubeClient kubernetes.Interface
)

func _init() {
Expand Down Expand Up @@ -172,6 +194,8 @@ func _init() {
"Optional, print version and exit.")
httpAddress = globalFlags.String("http-listen-address", "0.0.0.0:8080",
"Optional, address to serve http based informations (/metrics and /health).")
disableTeems = globalFlags.Bool("disable-teems", false,
"Optional, flag to disable sending telemetry data to TEEM")

globalFlags.Usage = func() {
fmt.Fprintf(os.Stderr, " Global:\n%s\n", globalFlags.FlagUsagesWrapped(width))
Expand Down Expand Up @@ -764,10 +788,13 @@ func main() {
log.Fatalf("error creating configuration: %v", err)
}
// creates the clientset
appMgrParms.KubeClient, err = kubernetes.NewForConfig(config)
kubeClient, err = kubernetes.NewForConfig(config)
if err != nil {
log.Fatalf("error connecting to the client: %v", err)
log.Fatalf("[INIT] error connecting to the client: %v", err)
os.Exit(1)
}
appMgrParms.KubeClient = kubeClient

if *manageRoutes {
var rclient *routeclient.RouteV1Client
rclient, err = routeclient.NewForConfig(config)
Expand All @@ -792,6 +819,58 @@ func main() {
}
appMgr.PostManager = postmanager.NewPostManager(postMgrParams)

// Adding the teems data
key, err := appMgr.PostManager.GetBigipRegKey()
if err != nil {
log.Debugf("Unable to get BigIP registration key %v", err)
}
td := &teem.TeemsData{
CisVersion: version,
Agent: *agent,
PoolMemberType: *poolMemberType,
PlatformInfo: getUserAgentInfo(),
DateOfCISDeploy: time.Now().UTC().Format(time.RFC3339Nano),
AccessEnabled: true,
ResourceType: teem.ResourceTypes{
Ingresses: make(map[string]int),
Routes: make(map[string]int),
Configmaps: make(map[string]int),
VirtualServer: make(map[string]int),
TransportServer: make(map[string]int),
ExternalDNS: make(map[string]int),
IngressLink: make(map[string]int),
IPAMVS: make(map[string]int),
IPAMTS: make(map[string]int),
IPAMSvcLB: make(map[string]int),
NativeRoutes: make(map[string]int),
RouteGroups: make(map[string]int),
},
}
if !(*disableTeems) {
if isNodePort {
td.SDNType = "nodeport-mode"
} else {
if len(*openshiftSDNName) > 0 {
td.SDNType = "openshiftSDN"
} else if len(*flannelName) > 0 {
td.SDNType = "flannel"
} else {
td.SDNType = "calico"
}
}

// Post telemetry data request
//if !td.PostTeemsData() {
// td.AccessEnabled = false
// log.Error("Unable to post data to TEEM server. Restart CIS once firewall rules permit")
//}
} else {
td.AccessEnabled = false
log.Debug("Telemetry data reporting to TEEM server is disabled")
}
td.RegistrationKey = key
appMgr.TeemData = td

// AS3 schema validation using latest AS3 version
fetchAS3Schema(appMgr)

Expand Down Expand Up @@ -879,3 +958,33 @@ func fallbackToLocalAS3Schema(appMgr *appmanager.Manager) {
appMgr.As3SchemaLatest = appMgr.SchemaLocalPath + as3SchemaFileName
return
}

// Get platform info for TEEM
func getUserAgentInfo() string {
var versionInfo map[string]string
var err error
var vInfo []byte
rc := kubeClient.Discovery().RESTClient()
// support for ocp < 3.11
if vInfo, err = rc.Get().AbsPath(versionPathOpenshiftv3).DoRaw(); err == nil {
if err = json.Unmarshal(vInfo, &versionInfo); err == nil {
return fmt.Sprintf("CIS/v%v OCP/%v", version, versionInfo["gitVersion"])
}
} else if vInfo, err = rc.Get().AbsPath(versionPathOpenshiftv4).DoRaw(); err == nil {
// support ocp > 4.0
var ocp4 Ocp4Version
if er := json.Unmarshal(vInfo, &ocp4); er == nil {
if len(ocp4.Status.History) > 0 {
return fmt.Sprintf("CIS/v%v OCP/v%v", version, ocp4.Status.History[0].Version)
}
return fmt.Sprintf("CIS/v%v OCP/v4.0.0", version)
}
} else if vInfo, err = rc.Get().AbsPath(versionPathk8s).DoRaw(); err == nil {
// support k8s
if er := json.Unmarshal(vInfo, &versionInfo); er == nil {
return fmt.Sprintf("CIS/v%v K8S/%v", version, versionInfo["gitVersion"])
}
}
log.Warningf("Unable to fetch user agent details. %v", err)
return fmt.Sprintf("CIS/v%v", version)
}
5 changes: 5 additions & 0 deletions docs/RELEASE-NOTES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Release Notes for BIG-IP Controller for Kubernetes
1.14.1
------------

Added Functionality
`````````````````````
* Added CIS deployment configuration option:
* ``--disable-teems`` - Configure to send anonymous analytics data to F5.

Vulnerability Fixes
```````````````````
Release image is upgrade to UBI-7 and following vulnerabilities are fixed:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ go 1.16

require (
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a // indirect
github.com/f5devcentral/go-bigip/f5teem v0.0.0-20210918163638-28fdd0579913
github.com/golang/groupcache v0.0.0-20170421005642-b710c8433bd1 // indirect
github.com/google/uuid v1.3.0
github.com/googleapis/gnostic v0.0.0-20190828010002-635450e9295f // indirect
github.com/matttproud/golang_protobuf_extensions v0.0.0-20160424113007-c12348ce28de // indirect
github.com/miekg/dns v1.1.42
Expand All @@ -28,5 +30,3 @@ require (
k8s.io/client-go v0.0.0-20191016111102-bec269661e48
k8s.io/utils v0.0.0-20190907131718-3d4f5b7dea0b // indirect
)


5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkg
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/evanphx/json-patch v4.2.0+incompatible h1:fUDGZCv/7iAN7u0puUVhvKCcsR6vRfwrJatElLBEf0I=
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/f5devcentral/go-bigip/f5teem v0.0.0-20210918163638-28fdd0579913 h1:/VVpfRxdUZk0l6mPOVxL8EDST8OnLepd1y33uxyYZrg=
github.com/f5devcentral/go-bigip/f5teem v0.0.0-20210918163638-28fdd0579913/go.mod h1:r7o5I22EvO+fps2u10bz4ZUlTlNHopQSWzVcW19hK3U=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
Expand Down Expand Up @@ -70,6 +72,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.0.0-20190828010002-635450e9295f h1:YUvZFTq7jrx3wTSpQaK8jjbx23TKnMm9KdXOjmUL3s0=
Expand Down Expand Up @@ -138,6 +142,7 @@ github.com/prometheus/common v0.0.0-20170707053319-3e6a7635bac6 h1:UEgo247BhzA25
github.com/prometheus/common v0.0.0-20170707053319-3e6a7635bac6/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/procfs v0.0.0-20170703101242-e645f4e5aaa8 h1:Kh7M6mzRpQ2de1rixoSQZr4BTINXFm8WDbeN5ttnwyE=
github.com/prometheus/procfs v0.0.0-20170703101242-e645f4e5aaa8/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
Expand Down
Loading

0 comments on commit c85a77d

Please sign in to comment.