Skip to content

Commit

Permalink
Add NetworkPolicy metrics API and controlplane stats API (#1221)
Browse files Browse the repository at this point in the history
This PR introduces a control-plane API NodeStatsSummary for stats
collection and a public metrics API group including the following APIs:
- NetworkPolicyMetrics
- AntreaClusterNetworkPolicyMetrics
- AntreaNetworkPolicyMetrics
  • Loading branch information
tnqn committed Sep 23, 2020
1 parent 70b360d commit 4e07577
Show file tree
Hide file tree
Showing 49 changed files with 6,019 additions and 9 deletions.
12 changes: 10 additions & 2 deletions hack/update-codegen-dockerized.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ $GOPATH/bin/client-gen \
--clientset-name versioned \
--input-base "${ANTREA_PKG}/pkg/apis/" \
--input "clusterinformation/v1beta1" \
--input "controlplane/v1alpha1" \
--input "controlplane/v1beta1" \
--input "system/v1beta1" \
--input "security/v1alpha1" \
--input "core/v1alpha1" \
--input "ops/v1alpha1" \
--input "metrics/v1alpha1" \
--output-package "${ANTREA_PKG}/pkg/client/clientset" \
--go-header-file hack/boilerplate/license_header.go.txt

Expand All @@ -57,23 +59,29 @@ $GOPATH/bin/informer-gen \
$GOPATH/bin/deepcopy-gen \
--input-dirs "${ANTREA_PKG}/pkg/apis/clusterinformation/v1beta1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/controlplane" \
--input-dirs "${ANTREA_PKG}/pkg/apis/controlplane/v1alpha1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/controlplane/v1beta1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/system/v1beta1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/security/v1alpha1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/core/v1alpha1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/ops/v1alpha1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/metrics" \
--input-dirs "${ANTREA_PKG}/pkg/apis/metrics/v1alpha1" \
-O zz_generated.deepcopy \
--go-header-file hack/boilerplate/license_header.go.txt

$GOPATH/bin/conversion-gen \
--input-dirs "${ANTREA_PKG}/pkg/apis/controlplane/v1beta1,${ANTREA_PKG}/pkg/apis/controlplane/" \
--input-dirs "${ANTREA_PKG}/pkg/apis/controlplane/v1alpha1,${ANTREA_PKG}/pkg/apis/controlplane/v1beta1,${ANTREA_PKG}/pkg/apis/controlplane/" \
--input-dirs "${ANTREA_PKG}/pkg/apis/metrics/v1alpha1,${ANTREA_PKG}/pkg/apis/metrics/" \
-O zz_generated.conversion \
--go-header-file hack/boilerplate/license_header.go.txt

$GOPATH/bin/openapi-gen \
--input-dirs "${ANTREA_PKG}/pkg/apis/controlplane/v1alpha1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/controlplane/v1beta1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/clusterinformation/v1beta1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/system/v1beta1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/metrics/v1alpha1" \
--input-dirs "k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/util/intstr" \
--input-dirs "k8s.io/api/core/v1" \
--output-package "${ANTREA_PKG}/pkg/apiserver/openapi" \
Expand Down Expand Up @@ -118,7 +126,7 @@ git checkout HEAD -- hack/boilerplate/license_header.raw.txt
go mod vendor
$GOPATH/bin/go-to-protobuf \
--proto-import vendor \
--packages "${ANTREA_PKG}/pkg/apis/controlplane/v1beta1" \
--packages "${ANTREA_PKG}/pkg/apis/metrics/v1alpha1,${ANTREA_PKG}/pkg/apis/controlplane/v1alpha1,${ANTREA_PKG}/pkg/apis/controlplane/v1beta1" \
--go-header-file hack/boilerplate/license_header.go.txt
# Clean up vendor directory.
rm -rf vendor
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/controlplane/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

"github.com/vmware-tanzu/antrea/pkg/apis/controlplane"
"github.com/vmware-tanzu/antrea/pkg/apis/controlplane/v1alpha1"
"github.com/vmware-tanzu/antrea/pkg/apis/controlplane/v1beta1"
)

// Install registers the API group and adds types to a scheme
func Install(scheme *runtime.Scheme) {
utilruntime.Must(controlplane.AddToScheme(scheme))
utilruntime.Must(v1alpha1.AddToScheme(scheme))
utilruntime.Must(v1beta1.AddToScheme(scheme))
utilruntime.Must(scheme.SetVersionPriority(v1beta1.SchemeGroupVersion))
}
23 changes: 23 additions & 0 deletions pkg/apis/controlplane/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"

metricsv1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/metrics/v1alpha1"
secv1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/security/v1alpha1"
)

Expand Down Expand Up @@ -268,3 +269,25 @@ type NetworkPolicyList struct {
metav1.ListMeta
Items []NetworkPolicy
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// NodeStatsSummary contains stats produced on a Node. It's used by the antrea-agents to report stats to the antrea-controller.
type NodeStatsSummary struct {
metav1.TypeMeta
metav1.ObjectMeta

// The TrafficStats of K8s NetworkPolicies collected from the Node.
NetworkPolicies []NetworkPolicyStats
// The TrafficStats of Antrea ClusterNetworkPolicies collected from the Node.
AntreaClusterNetworkPolicies []NetworkPolicyStats
// The TrafficStats of Antrea NetworkPolicies collected from the Node.
AntreaNetworkPolicies []NetworkPolicyStats
}

// NetworkPolicyStats contains the information and traffic stats of a NetworkPolicy.
type NetworkPolicyStats struct {
// The reference of the NetworkPolicy.
NetworkPolicy NetworkPolicyReference
// The stats of the NetworkPolicy.
TrafficStats metricsv1alpha1.TrafficStats
}
23 changes: 23 additions & 0 deletions pkg/apis/controlplane/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2020 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.

// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package
// +k8s:protobuf-gen=package
// +k8s:conversion-gen=github.com/vmware-tanzu/antrea/pkg/apis/controlplane
// +groupName=controlplane.antrea.tanzu.vmware.com

// Package v1alpha1 is the v1alpha1 version of the Antrea controlplane API.

package v1alpha1
Loading

0 comments on commit 4e07577

Please sign in to comment.