Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the antctl framework #208

Merged
merged 7 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.cache
bin/antctl-darwin
bin/antctl-linux
bin/antctl-windows.exe
16 changes: 16 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ jobs:
- name: Build Antrea binaries
run: make bin

antctl:
name: Build antctl for macOS, Linux and Windows
runs-on: [ubuntu-18.04]
steps:

- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13

- name: Check-out code
uses: actions/checkout@v1

- name: Build antctl binaries
run: make antctl


codegen:
name: Check code generation
Expand Down
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
SHELL := /bin/bash
# go options
GO ?= go
LDFLAGS :=
Expand Down Expand Up @@ -75,6 +76,19 @@ docker-tidy: $(DOCKER_CACHE)
.linux-bin:
GOBIN=$(BINDIR) $(GO) install $(GOFLAGS) -ldflags '$(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/...

# TODO: strip binary when building releases
ANTCTL_BINARIES := antctl-darwin antctl-linux antctl-windows
weiqiangt marked this conversation as resolved.
Show resolved Hide resolved
$(ANTCTL_BINARIES): antctl-%:
@GOOS=$* $(GO) build -o $(BINDIR)/$@ $(GOFLAGS) -ldflags '$(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/antctl
@if [[ $@ != *windows ]]; then \
chmod 0755 $(BINDIR)/$@; \
else \
mv $(BINDIR)/$@ $(BINDIR)/$@.exe; \
fi

.PHONY: antctl
antctl: $(ANTCTL_BINARIES)

.PHONY: .linux-test-unit
.linux-test-unit:
@echo
Expand Down
53 changes: 53 additions & 0 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ spec:
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app: antrea
name: antctl
namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app: antrea
Expand All @@ -56,6 +64,19 @@ metadata:
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app: antrea
name: antctl
rules:
- nonResourceURLs:
- /apis/system.antrea.tanzu.vmware.com
- /apis/system.antrea.tanzu.vmware.com/*
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app: antrea
Expand Down Expand Up @@ -146,6 +167,22 @@ rules:
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
labels:
app: antrea
name: antctl
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: antctl
subjects:
- kind: ServiceAccount
name: antctl
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
labels:
app: antrea
Expand Down Expand Up @@ -336,6 +373,22 @@ spec:
name: antrea-config-k5f958t9km
name: antrea-config
---
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
labels:
app: antrea
name: v1beta1.system.antrea.tanzu.vmware.com
spec:
group: system.antrea.tanzu.vmware.com
groupPriorityMinimum: 100
insecureSkipTLSVerify: true
service:
name: antrea
namespace: kube-system
version: v1beta1
versionPriority: 100
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
Expand Down
53 changes: 53 additions & 0 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ spec:
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app: antrea
name: antctl
namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app: antrea
Expand All @@ -56,6 +64,19 @@ metadata:
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app: antrea
name: antctl
rules:
- nonResourceURLs:
- /apis/system.antrea.tanzu.vmware.com
- /apis/system.antrea.tanzu.vmware.com/*
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app: antrea
Expand Down Expand Up @@ -146,6 +167,22 @@ rules:
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
labels:
app: antrea
name: antctl
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: antctl
subjects:
- kind: ServiceAccount
name: antctl
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
labels:
app: antrea
Expand Down Expand Up @@ -327,6 +364,22 @@ spec:
name: antrea-config-tm7bht9mg6
name: antrea-config
---
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
labels:
app: antrea
name: v1beta1.system.antrea.tanzu.vmware.com
spec:
group: system.antrea.tanzu.vmware.com
groupPriorityMinimum: 100
insecureSkipTLSVerify: true
service:
name: antrea
namespace: kube-system
version: v1beta1
versionPriority: 100
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
Expand Down
33 changes: 33 additions & 0 deletions build/yamls/base/antctl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
weiqiangt marked this conversation as resolved.
Show resolved Hide resolved
apiVersion: v1
kind: ServiceAccount
metadata:
name: antctl
namespace: kube-system
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: antctl
rules:
- nonResourceURLs:
- /apis/system.antrea.tanzu.vmware.com
- /apis/system.antrea.tanzu.vmware.com/*
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
labels:
app: antrea
name: antctl
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: antctl
subjects:
- kind: ServiceAccount
name: antctl
namespace: kube-system
14 changes: 14 additions & 0 deletions build/yamls/base/controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ spec:
selector:
component: antrea-controller
---
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1beta1.system.antrea.tanzu.vmware.com
spec:
insecureSkipTLSVerify: true
group: system.antrea.tanzu.vmware.com
groupPriorityMinimum: 100
version: v1beta1
versionPriority: 100
service:
name: antrea
namespace: kube-system
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
1 change: 1 addition & 0 deletions build/yamls/base/kustomization.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
resources:
- crds.yml
- antctl.yml
- controller-rbac.yml
- controller.yml
- agent-rbac.yml
Expand Down
60 changes: 60 additions & 0 deletions cmd/antctl/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2019 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 main

import (
"flag"
"os"
"path"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/component-base/logs"

"github.com/vmware-tanzu/antrea/pkg/antctl"
)

var (
commandName = path.Base(os.Args[0])
// TODO: May not work for antrea on windows
inPod = len(os.Getenv("POD_NAME")) != 0
isAgent = strings.HasPrefix(os.Getenv("POD_NAME"), "antrea-agent")
)

var rootCmd = &cobra.Command{
Use: commandName,
Short: commandName + " is the command line tool for Antrea",
Long: commandName + " is the command line tool for Antrea that supports showing status of ${component}",
}

func init() {
// prevent any unexpected output at beginning
flag.Set("logtostderr", "false")
flag.Set("v", "0")
pflag.CommandLine.MarkHidden("log-flush-frequency")
}

func main() {
logs.InitLogs()
defer logs.FlushLogs()

antctl.CommandList.ApplyToRootCommand(rootCmd, isAgent, inPod)
err := rootCmd.Execute()
if err != nil {
logs.FlushLogs()
os.Exit(1)
weiqiangt marked this conversation as resolved.
Show resolved Hide resolved
}
}
8 changes: 8 additions & 0 deletions cmd/antrea-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/vmware-tanzu/antrea/pkg/agent/controller/noderoute"
"github.com/vmware-tanzu/antrea/pkg/agent/interfacestore"
"github.com/vmware-tanzu/antrea/pkg/agent/openflow"
"github.com/vmware-tanzu/antrea/pkg/antctl"
"github.com/vmware-tanzu/antrea/pkg/apis/networking/v1beta1"
"github.com/vmware-tanzu/antrea/pkg/k8s"
"github.com/vmware-tanzu/antrea/pkg/monitor"
Expand Down Expand Up @@ -89,6 +90,11 @@ func run(o *Options) error {
}
nodeConfig := agentInitializer.GetNodeConfig()

antctlServer, err := antctl.NewLocalServer()
if err != nil {
return fmt.Errorf("error when creating local antctl server: %w", err)
}

nodeRouteController := noderoute.NewNodeRouteController(
k8sClient,
informerFactory,
Expand Down Expand Up @@ -138,6 +144,8 @@ func run(o *Options) error {

go agentMonitor.Run(stopCh)

antctlServer.Start(agentMonitor, nil, stopCh)

<-stopCh
klog.Info("Stopping Antrea agent")
return nil
Expand Down
Loading