This repository was archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 193
Add antrea-interworking package #4510
Open
wenqiq
wants to merge
2
commits into
main
Choose a base branch
from
topic/wenqi/antrea-interworking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,10 @@ package controllers | |
import ( | ||
"context" | ||
"fmt" | ||
"reflect" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"golang.org/x/mod/semver" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1" | ||
|
@@ -23,54 +23,84 @@ import ( | |
cniv1alpha2 "github.com/vmware-tanzu/tanzu-framework/apis/addonconfigs/cni/v1alpha2" | ||
) | ||
|
||
const ( | ||
bootstrapFromInline = "Inline" | ||
bootstrapFromSupervisorCluster = "SupervisorCluster" | ||
) | ||
|
||
// AntreaConfigSpec defines the desired state of AntreaConfig | ||
type AntreaConfigSpec struct { | ||
InfraProvider string `yaml:"infraProvider"` | ||
Antrea antrea `yaml:"antrea,omitempty"` | ||
AntreaNsx antreaNsx `yaml:"antreaNsx,omitempty"` | ||
InfraProvider string `yaml:"infraProvider"` | ||
Antrea antrea `yaml:"antrea,omitempty"` | ||
AntreaNsx antreaNsx `yaml:"antrea_nsx,omitempty"` | ||
AntreaInterworking antreaInterworking `yaml:"antrea_interworking,omitempty"` | ||
} | ||
|
||
type antrea struct { | ||
AntreaConfigDataValue antreaConfigDataValue `yaml:"config,omitempty"` | ||
} | ||
|
||
type antreaNsx struct { | ||
Enable bool `yaml:"enable,omitempty"` | ||
BootstrapFrom antreaNsxBootstrapFrom `yaml:"bootstrapFrom,omitempty"` | ||
AntreaNsxConfig antreaNsxConfig `yaml:"config,omitempty"` | ||
type antreaInterworking struct { | ||
Config antreaInterworkingConfig `yaml:"config,omitempty"` | ||
} | ||
|
||
type antreaNsxBootstrapFrom struct { | ||
// ProviderRef is used with uTKG, which will be filled by NCP operator | ||
ProviderRef *antreaNsxProvider `yaml:"providerRef,omitempty"` | ||
// Inline is used with TKGm, user need to fill in manually | ||
Inline *antreaNsxInline `yaml:"inline,omitempty"` | ||
type antreaNsx struct { | ||
Enable bool `yaml:"enable,omitempty"` | ||
} | ||
|
||
type antreaNsxProvider struct { | ||
// Api version for nsxServiceAccount, its value is "nsx.vmware.com/v1alpha1" now | ||
ApiVersion string `yaml:"apiVersion,omitempty"` | ||
// Its value is NsxServiceAccount | ||
Kind string `yaml:"kind,omitempty"` | ||
// Name is the name for NsxServiceAccount | ||
Name string `yaml:"name,omitempty"` | ||
type antreaInterworkingConfig struct { | ||
InfraType string `yaml:"infraType,omitempty"` | ||
BootstrapFrom string `yaml:"bootstrapFrom,omitempty"` | ||
BootstrapSupervisorResourceName string `yaml:"bootstrapSupervisorResourceName,omitempty"` | ||
NSXCert string `yaml:"nsxCert,omitempty"` | ||
NSXKey string `yaml:"nsxKey,omitempty"` | ||
ClusterName string `yaml:"clusterName,omitempty"` | ||
NSXManagers []string `yaml:"NSXManagers,omitempty"` | ||
VPCPath []string `yaml:"vpcPath,omitempty"` | ||
ProxyEndpoints proxyEndpoints `yaml:"proxyEndpoints,omitempty"` | ||
MpAdapterConf mpAdapterConf `yaml:"mp_adapter_conf,omitempty"` | ||
CcpAdapterConf ccpAdapterConf `yaml:"ccp_adapter_conf,omitempty"` | ||
} | ||
|
||
type nsxCertRef struct { | ||
// TLSCert is cert file to access nsx manager | ||
TLSCert string `yaml:"tls.crt,omitempty"` | ||
// TLSKey is key file to access nsx manager | ||
TLSKey string `yaml:"tls.key,omitempty"` | ||
type proxyEndpoints struct { | ||
RestApi []string `yaml:"rest_api,omitempty"` | ||
NSXRpcFwdProxy []string `yaml:"nsx_rpc_fwd_proxy,omitempty"` | ||
} | ||
|
||
type antreaNsxInline struct { | ||
NsxManagers []string `yaml:"nsxManagers,omitempty"` | ||
ClusterName string `yaml:"clusterName,omitempty"` | ||
NsxCertRef nsxCertRef `yaml:"NsxCert,omitempty"` | ||
type mpAdapterConf struct { | ||
NSXClientAuthCertFile string `yaml:"NSXClientAuthCertFile,omitempty"` | ||
NSXClientAuthKeyFile string `yaml:"NSXClientAuthKeyFile,omitempty"` | ||
NSXRemoteAuth bool `yaml:"NSXRemoteAuth,omitempty"` | ||
NSXCAFile string `yaml:"NSXCAFile,omitempty"` | ||
NSXInsecure bool `yaml:"NSXInsecure,omitempty"` | ||
NSXRPCConnType string `yaml:"NSXRPCConnType,omitempty"` | ||
ClusterType string `yaml:"clusterType,omitempty"` | ||
NSXClientTimeout int `yaml:"NSXClientTimeout,omitempty"` | ||
InventoryBatchSize int `yaml:"InventoryBatchSize,omitempty"` | ||
InventoryBatchPeriod int `yaml:"InventoryBatchPeriod,omitempty"` | ||
EnableDebugServer bool `yaml:"EnableDebugServer,omitempty"` | ||
APIServerPort int `yaml:"APIServerPort,omitempty"` | ||
DebugServerPort int `yaml:"DebugServerPort,omitempty"` | ||
NSXRPCDebug bool `yaml:"NSXRPCDebug,omitempty"` | ||
ConditionTimeout int `yaml:"ConditionTimeout,omitempty"` | ||
} | ||
|
||
type antreaNsxConfig struct { | ||
InfraType string `yaml:"infraType,omitempty"` | ||
type ccpAdapterConf struct { | ||
EnableDebugServer bool `yaml:"EnableDebugServer,omitempty"` | ||
APIServerPort int `yaml:"APIServerPort,omitempty"` | ||
DebugServerPort int `yaml:"DebugServerPort,omitempty"` | ||
NSXRPCDebug bool `yaml:"NSXRPCDebug,omitempty"` | ||
// Time to wait for realization | ||
RealizeTimeoutSeconds int `yaml:"RealizeTimeoutSeconds,omitempty"` | ||
// An interval for regularly report latest realization error in background | ||
RealizeErrorSyncIntervalSeconds int `yaml:"RealizeErrorSyncIntervalSeconds,omitempty"` | ||
ReconcilerWorkerCount int `yaml:"ReconcilerWorkerCount,omitempty"` | ||
// Average QPS = ReconcilerWorkerCount * ReconcilerQPS | ||
ReconcilerQPS int `yaml:"ReconcilerQPS,omitempty"` | ||
// Peak QPS = ReconcilerWorkerCount * ReconcilerBurst | ||
ReconcilerBurst int `yaml:"ReconcilerBurst,omitempty"` | ||
// #! 24 Hours | ||
ReconcilerResyncSeconds int `yaml:"ReconcilerResyncSeconds,omitempty"` | ||
} | ||
|
||
type antreaEgress struct { | ||
|
@@ -300,6 +330,52 @@ func mapAntreaConfigSpec(cluster *clusterv1beta1.Cluster, config *cniv1alpha2.An | |
if semver.Compare(version, "v1.9.0") >= 0 { | ||
configSpec.Antrea.AntreaConfigDataValue.FeatureGates.TopologyAwareHints = &config.Spec.Antrea.AntreaConfigDataValue.FeatureGates.TopologyAwareHints | ||
} | ||
// NSX related | ||
if semver.Compare(version, "1.9.0") >= 0 && config.Spec.AntreaNsx.Enable { | ||
configSpec.AntreaNsx.Enable = config.Spec.AntreaNsx.Enable | ||
if config.Spec.AntreaInterworking.Config.BootstrapFrom == bootstrapFromInline { | ||
configSpec.AntreaInterworking.Config.NSXManagers = config.Spec.AntreaInterworking.Config.NSXManagers | ||
configSpec.AntreaInterworking.Config.ClusterName = config.Spec.AntreaInterworking.Config.ClusterName | ||
configSpec.AntreaInterworking.Config.NSXCert = config.Spec.AntreaInterworking.Config.NSXCert | ||
configSpec.AntreaInterworking.Config.NSXKey = config.Spec.AntreaInterworking.Config.NSXKey | ||
configSpec.AntreaInterworking.Config.VPCPath = config.Spec.AntreaInterworking.Config.VPCPath | ||
configSpec.AntreaInterworking.Config.ProxyEndpoints.NSXRpcFwdProxy = config.Spec.AntreaInterworking.Config.ProxyEndpoints.NSXRpcFwdProxy | ||
configSpec.AntreaInterworking.Config.ProxyEndpoints.RestApi = config.Spec.AntreaInterworking.Config.ProxyEndpoints.RestApi | ||
} else { | ||
configSpec.AntreaInterworking.Config.BootstrapFrom = bootstrapFromSupervisorCluster | ||
configSpec.AntreaInterworking.Config.BootstrapSupervisorResourceName = getNSXServiceAccountName(cluster.Name) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any else branch required here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this pr #4219 can be merged into v0.28, this should also be included in v0.28 |
||
|
||
ccpConf := config.Spec.AntreaInterworking.Config.CcpAdapterConf | ||
if err := copyStructAtoB(ccpConf, &configSpec.AntreaInterworking.Config.CcpAdapterConf); err != nil { | ||
return configSpec, err | ||
} | ||
mpConf := config.Spec.AntreaInterworking.Config.MpAdapterConf | ||
if err := copyStructAtoB(mpConf, &configSpec.AntreaInterworking.Config.MpAdapterConf); err != nil { | ||
return configSpec, err | ||
} | ||
} | ||
|
||
return configSpec, nil | ||
} | ||
|
||
func copyStructAtoB(a interface{}, b interface{}) error { | ||
va := reflect.ValueOf(a) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reflect can make it more feasible, but at same time it can introduce performance cost, maybe consider if the implementation is OK. |
||
vb := reflect.ValueOf(b).Elem() | ||
for i := 0; i < va.NumField(); i++ { | ||
fieldA := va.Field(i) | ||
fieldB := vb.FieldByName(va.Type().Field(i).Name) | ||
if fieldB.IsValid() && fieldA.Type() == fieldB.Type() { | ||
fieldB.Set(fieldA) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func getProviderServiceAccountName(clusterName string) string { | ||
return fmt.Sprintf("%s-antrea", clusterName) | ||
} | ||
|
||
func getNSXServiceAccountName(clusterName string) string { | ||
return fmt.Sprintf("%s-antrea", clusterName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package controllers | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/vmware-tanzu/tanzu-framework/apis/addonconfigs/cni/v1alpha2" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCopyStruct(t *testing.T) { | ||
ccpConf := v1alpha2.CcpAdapterConf{ | ||
EnableDebugServer: true, | ||
APIServerPort: 1234, | ||
} | ||
descCcpAdapterConf := ccpAdapterConf{ | ||
EnableDebugServer: false, | ||
APIServerPort: 0, | ||
} | ||
err := copyStructAtoB(ccpConf, &descCcpAdapterConf) | ||
require.NoError(t, err, "copy CcpAdapterConf values error") | ||
assert.Equal(t, 1234, descCcpAdapterConf.APIServerPort) | ||
assert.Equal(t, true, descCcpAdapterConf.EnableDebugServer) | ||
|
||
mpConf := v1alpha2.MpAdapterConf{ | ||
NSXClientAuthCertFile: "fake-cert-file", | ||
ConditionTimeout: 150, | ||
} | ||
descMpAdapterConf := mpAdapterConf{ | ||
NSXClientAuthCertFile: "", | ||
ConditionTimeout: 0, | ||
} | ||
err = copyStructAtoB(mpConf, &descMpAdapterConf) | ||
require.NoError(t, err, "copy MpAdapterConf values error") | ||
assert.Equal(t, "fake-cert-file", descMpAdapterConf.NSXClientAuthCertFile) | ||
assert.Equal(t, 150, descMpAdapterConf.ConditionTimeout) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,5 +94,5 @@ spec: | |
AntreaIPAM: false | ||
ServiceExternalIP: false | ||
Multicast: false | ||
antreaNsx: | ||
antrea_nsx: | ||
enable: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AntreaConfigSpec should be aligned with Antrea package schema.yaml.
The AntreaNSX member in this struct needs to be renamed as antrea_nsx, and
yaml:"antreaNsx,omitempty"
needs to be changed toyaml:"antrea_nsx,omitempty"
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.