Skip to content

Commit

Permalink
Implementation of theia and policy recommendation CLI
Browse files Browse the repository at this point in the history
In this commit, we add the implementation of theia, the command-line
tool for Theia based on cobra framework.
Policy recommendation CLI is also included. It consists of 3 commands
which let users could run a new policy recommendation job, check the
current status of a previous job, and retrieve the recommendation
result of a previous job respectively.
In order to access theia services externally, theia can
make use of k8s port forwarder functionality. Port forwarder
provides tooling to start/stop port forwarding channel for
eather Pod+Port or Service+Port. The code is loosely based on
corresponding code in kubectl.
Document of theia and policy recommendation will be added in a seperate
commit later.

Signed-off-by: Yongming Ding <dyongming@vmware.com>
Co-authored-by: Yanjun Zhou <zhouya@vmware.com>
Co-authored-by: Anna Khmelnitsky <akhmelnitsky@vmware.com>

Address comments

Signed-off-by: Yongming Ding <dyongming@vmware.com>
  • Loading branch information
Yongming Ding committed Jun 6, 2022
1 parent 75f6968 commit 6806eab
Show file tree
Hide file tree
Showing 20 changed files with 3,555 additions and 12 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/upload_release_assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,48 @@ jobs:
asset_path: ./assets/flow-visibility.yml
asset_name: flow-visibility.yml
asset_content_type: application/octet-stream
- name: Upload theia-darwin-x86_64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./assets/theia-darwin-x86_64
asset_name: theia-darwin-x86_64
asset_content_type: application/octet-stream
- name: Upload theia-linux-arm
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./assets/theia-linux-arm
asset_name: theia-linux-arm
asset_content_type: application/octet-stream
- name: Upload theia-linux-arm64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./assets/theia-linux-arm64
asset_name: theia-linux-arm64
asset_content_type: application/octet-stream
- name: Upload theia-linux-x86_64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./assets/theia-linux-x86_64
asset_name: theia-linux-x86_64
asset_content_type: application/octet-stream
- name: Upload theia-windows-x86_64.exe
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./assets/theia-windows-x86_64.exe
asset_name: theia-windows-x86_64.exe
asset_content_type: application/octet-stream
35 changes: 26 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
SHELL := /bin/bash
SHELL := /bin/bash
# go options
GO ?= go
LDFLAGS :=
GOFLAGS :=
BINDIR ?= $(CURDIR)/bin
GO_FILES := $(shell find . -type d -name '.cache' -prune -o -type f -name '*.go' -print)
GOPATH ?= $$($(GO) env GOPATH)
DOCKER_CACHE := $(CURDIR)/.cache
GO_VERSION := $(shell head -n 1 build/images/deps/go-version)
GO ?= go
LDFLAGS :=
GOFLAGS :=
BINDIR ?= $(CURDIR)/bin
GO_FILES := $(shell find . -type d -name '.cache' -prune -o -type f -name '*.go' -print)
GOPATH ?= $$($(GO) env GOPATH)
DOCKER_CACHE := $(CURDIR)/.cache
THEIA_BINARY_NAME ?= theia
GO_VERSION := $(shell head -n 1 build/images/deps/go-version)

DOCKER_BUILD_ARGS = --build-arg GO_VERSION=$(GO_VERSION)

Expand Down Expand Up @@ -165,3 +166,19 @@ policy-recommendation:
docker tag antrea/theia-policy-recommendation:$(DOCKER_IMG_VERSION) antrea/theia-policy-recommendation
docker tag antrea/theia-policy-recommendation:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/theia-policy-recommendation
docker tag antrea/theia-policy-recommendation:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/theia-policy-recommendation:$(DOCKER_IMG_VERSION)

THEIA_BINARIES := theia-darwin theia-linux theia-windows
$(THEIA_BINARIES): theia-%:
@GOOS=$* $(GO) build -o $(BINDIR)/$@ $(GOFLAGS) -ldflags '$(LDFLAGS)' antrea.io/theia/pkg/theia
@if [[ $@ != *windows ]]; then \
chmod 0755 $(BINDIR)/$@; \
else \
mv $(BINDIR)/$@ $(BINDIR)/$@.exe; \
fi

.PHONY: theia
theia: $(THEIA_BINARIES)

.PHONY: theia-release
theia-release:
@$(GO) build -o $(BINDIR)/$(THEIA_BINARY_NAME) $(GOFLAGS) -ldflags '-s -w $(LDFLAGS)' antrea.io/theia/pkg/theia
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ require (
github.com/ClickHouse/clickhouse-go v1.5.4
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/containernetworking/plugins v0.8.7
github.com/google/uuid v1.1.2
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.4.0
github.com/stretchr/testify v1.7.0
github.com/vmware/go-ipfix v0.5.12
golang.org/x/crypto v0.0.0-20210503195802-e9a32991a82e
Expand Down Expand Up @@ -60,7 +62,6 @@ require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
Expand Down Expand Up @@ -88,7 +89,6 @@ require (
github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cobra v1.4.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/streamrail/concurrent-map v0.0.0-20160823150647-8bf1e9bacbf6 // indirect
github.com/vishvananda/netlink v1.1.1-0.20210510164352-d17758a128bf // indirect
Expand Down
21 changes: 21 additions & 0 deletions hack/release/prepare-assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ pushd $THIS_DIR/../.. > /dev/null
mkdir -p "$1"
OUTPUT_DIR=$(cd "$1" && pwd)

THEIA_BUILDS=(
"linux amd64 linux-x86_64"
"linux arm64 linux-arm64"
"linux arm linux-arm"
"windows amd64 windows-x86_64.exe"
"darwin amd64 darwin-x86_64"
)

for build in "${THEIA_BUILDS[@]}"; do
args=($build)
os="${args[0]}"
arch="${args[1]}"
suffix="${args[2]}"

# cgo is disabled by default when cross-compiling, but enabled by default
# for native builds. We ensure it is always disabled for portability since
# these binaries will be distributed as release assets.
GOOS=$os GOARCH=$arch CGO_ENABLED=0 THEIA_BINARY_NAME="theia-$suffix" BINDIR="$OUTPUT_DIR"/ make theia-release
done


export IMG_TAG=$VERSION

export IMG_NAME=projects.registry.vmware.com/antrea/theia-clickhouse-monitor
Expand Down
43 changes: 43 additions & 0 deletions pkg/theia/commands/policy_recommendation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2022 Antrea Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package commands

import (
"fmt"

"github.com/spf13/cobra"
)

// policyRecommendationCmd represents the policy recommendation command group
var policyRecommendationCmd = &cobra.Command{
Use: "policy-recommendation",
Aliases: []string{"pr"},
Short: "Commands of Theia policy recommendation feature",
Long: `Command group of Theia policy recommendation feature.
Must specify a subcommand like run, status or retrieve.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Error: must also specify a subcommand like run, status or retrieve")
},
}

func init() {
rootCmd.AddCommand(policyRecommendationCmd)
rootCmd.PersistentFlags().StringP(
"kubeconfig",
"k",
"",
"absolute path to the k8s config file, will use $KUBECONFIG if not specified",
)
}
Loading

0 comments on commit 6806eab

Please sign in to comment.