Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
make antreaConfig structs public
Browse files Browse the repository at this point in the history
Signed-off-by: Bin Liu <[email protected]>
  • Loading branch information
liu4480 committed Dec 5, 2022
1 parent 093d1ad commit aee41f0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 57 deletions.
66 changes: 30 additions & 36 deletions addons/controllers/antrea/antreaconfig_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,27 @@ import (
)

// AntreaConfigSpec defines the desired state of AntreaConfig
type antreaConfigSpec struct {
type AntreaConfigSpec struct {
InfraProvider string `yaml:"infraProvider"`
Antrea antrea `yaml:"antrea,omitempty"`
AntreaNsx antreaNsx `yaml:"antreaNsx,omitempty"`
Antrea Antrea `yaml:"antrea,omitempty"`
AntreaNsx AntreaNsx `yaml:"antreaNsx,omitempty"`
}

type antrea struct {
type Antrea struct {
AntreaConfigDataValue antreaConfigDataValue `yaml:"config,omitempty"`
}

type antreaNsx struct {
type AntreaNsx struct {
Enable bool `yaml:"enable,omitempty"`
BootstrapFrom AntreaNsxBootstrapFrom `yaml:"bootstrapFrom,omitempty"`
AntreaNsxConfig antreaNsxConfig `yaml:"config,omitempty"`
}

type antreaNsxProvider struct {
ApiVersion string `yaml:"apiVersion,omitempty"`
Kind string `yaml:"kind,omitempty"`
Name string `yaml:"kind,omitempty"`
AntreaNsxConfig AntreaNsxConfig `yaml:"config,omitempty"`
}

type AntreaNsxBootstrapFrom struct {
// ProviderRef is used with uTKG, which will be filled by NCP operator
ProviderRef *antreaNsxProvider `yaml:"providerRef,omitempty"`
ProviderRef *AntreaNsxProvider `yaml:"providerRef,omitempty"`
// Inline is used with TKGm, user need to fill in manually
Inline *antreaNsxInline `yaml:"inline,omitempty"`
Inline *AntreaNsxInline `yaml:"inline,omitempty"`
}

type AntreaNsxProvider struct {
Expand All @@ -58,74 +52,74 @@ type AntreaNsxProvider struct {
Name string `yaml:"name,omitempty"`
}

type nsxCertRef struct {
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 antreaNsxInline struct {
type AntreaNsxInline struct {
NsxManagers []string `yaml:"nsxManagers,omitempty"`
ClusterName string `yaml:"clusterName,omitempty"`
NsxCertRef nsxCertRef `yaml:"NsxCert,omitempty"`
NsxCertRef NsxCertRef `yaml:"NsxCert,omitempty"`
}

type antreaNsxConfig struct {
type AntreaNsxConfig struct {
InfraType string `yaml:"infraType,omitempty"`
}

type antreaEgress struct {
type AntreaEgress struct {
EgressExceptCIDRs []string `yaml:"exceptCIDRs,omitempty"`
}

type antreaNodePortLocal struct {
type AntreaNodePortLocal struct {
Enabled bool `yaml:"enabled,omitempty"`
PortRange string `yaml:"portRange,omitempty"`
}

type antreaProxy struct {
type AntreaProxy struct {
ProxyAll bool `yaml:"proxyAll,omitempty"`
NodePortAddresses []string `yaml:"nodePortAddresses,omitempty"`
SkipServices []string `yaml:"skipServices,omitempty"`
ProxyLoadBalancerIPs bool `yaml:"proxyLoadBalancerIPs,omitempty"`
}

type antreaFlowExporter struct {
type AntreaFlowExporter struct {
CollectorAddress string `yaml:"collectorAddress,omitempty"`
PollInterval string `yaml:"pollInterval,omitempty"`
ActiveFlowTimeout string `yaml:"activeFlowTimeout,omitempty"`
IdleFlowTimeout string `yaml:"idleFlowTimeout,omitempty"`
}

type antreaMultiCluster struct {
type AntreaMultiCluster struct {
Enable bool `yaml:"enable,omitempty"`
Namespace string `yaml:"namespace,omitempty"`
}

type antreaMulticast struct {
type AntreaMulticast struct {
IGMPQueryInterval string `yaml:"igmpQueryInterval,omitempty"`
}

type antreaWireGuard struct {
type AntreaWireGuard struct {
Port int `yaml:"port,omitempty"`
}

type antreaConfigDataValue struct {
Egress antreaEgress `yaml:"egress,omitempty"`
NodePortLocal antreaNodePortLocal `yaml:"nodePortLocal,omitempty"`
AntreaProxy antreaProxy `yaml:"antreaProxy,omitempty"`
FlowExporter antreaFlowExporter `yaml:"flowExporter,omitempty"`
Multicast antreaMulticast `yaml:"multicast,omitempty"`
MultiCluster antreaMultiCluster `yaml:"multicluster,omitempty"`
Egress AntreaEgress `yaml:"egress,omitempty"`
NodePortLocal AntreaNodePortLocal `yaml:"nodePortLocal,omitempty"`
AntreaProxy AntreaProxy `yaml:"antreaProxy,omitempty"`
FlowExporter AntreaFlowExporter `yaml:"flowExporter,omitempty"`
Multicast AntreaMulticast `yaml:"multicast,omitempty"`
MultiCluster AntreaMultiCluster `yaml:"multicluster,omitempty"`
KubeAPIServerOverride string `yaml:"kubeAPIServerOverride,omitempty"`
TransportInterface string `yaml:"transportInterface,omitempty"`
TransportInterfaceCIDRs []string `yaml:"transportInterfaceCIDRs,omitempty"`
MulticastInterfaces []string `yaml:"multicastInterfaces,omitempty"`
TunnelType string `yaml:"tunnelType,omitempty"`
TrafficEncryptionMode string `yaml:"trafficEncryptionMode,omitempty"`
EnableUsageReporting bool `yaml:"enableUsageReporting,omitempty"`
WireGuard antreaWireGuard `yaml:"wireGuard,omitempty"`
WireGuard AntreaWireGuard `yaml:"wireGuard,omitempty"`
ServiceCIDR string `yaml:"serviceCIDR,omitempty"`
ServiceCIDRv6 string `yaml:"serviceCIDRv6,omitempty"`
TrafficEncapMode string `yaml:"trafficEncapMode,omitempty"`
Expand All @@ -136,10 +130,10 @@ type antreaConfigDataValue struct {
EnableBridgingMode bool `yaml:"enableBridgingMode,omitempty"`
DisableTXChecksumOffload bool `yaml:"disableTXChecksumOffload,omitempty"`
DNSServerOverride string `yaml:"dnsServerOverride,omitempty"`
FeatureGates antreaFeatureGates `yaml:"featureGates,omitempty"`
FeatureGates AntreaFeatureGates `yaml:"featureGates,omitempty"`
}

type antreaFeatureGates struct {
type AntreaFeatureGates struct {
AntreaProxy bool `yaml:"AntreaProxy"`
EndpointSlice bool `yaml:"EndpointSlice"`
AntreaPolicy bool `yaml:"AntreaPolicy"`
Expand Down Expand Up @@ -207,8 +201,8 @@ func (r *AntreaConfigReconciler) ClusterToAntreaConfig(o client.Object) []ctrl.R
return requests
}

func mapAntreaConfigSpec(cluster *clusterv1beta1.Cluster, config *cniv1alpha1.AntreaConfig, client client.Client) (*antreaConfigSpec, error) {
configSpec := &antreaConfigSpec{}
func mapAntreaConfigSpec(cluster *clusterv1beta1.Cluster, config *cniv1alpha1.AntreaConfig, client client.Client) (*AntreaConfigSpec, error) {
configSpec := &AntreaConfigSpec{}

// Derive InfraProvider from the cluster
infraProvider, err := util.GetInfraProvider(cluster)
Expand Down
49 changes: 28 additions & 21 deletions addons/controllers/antreaconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ package controllers
import (
"fmt"
"os"
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"gopkg.in/yaml.v3"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
capvvmwarev1beta1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/vmware/v1beta1"
clusterapiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"

antreatype "github.com/vmware-tanzu/tanzu-framework/addons/controllers/antrea"
cutil "github.com/vmware-tanzu/tanzu-framework/addons/controllers/utils"
"github.com/vmware-tanzu/tanzu-framework/addons/pkg/constants"
"github.com/vmware-tanzu/tanzu-framework/addons/pkg/util"
Expand Down Expand Up @@ -183,16 +184,19 @@ var _ = Describe("AntreaConfig Reconciler and Webhooks", func() {
Expect(secret.Type).Should(Equal(v1.SecretTypeOpaque))

// check data value secret contents
secretData := string(secret.Data["values.yaml"])

Expect(strings.Contains(secretData, "serviceCIDR: 192.168.0.0/16")).Should(BeTrue())
Expect(strings.Contains(secretData, "serviceCIDRv6: fd00:100:96::/48")).Should(BeTrue())
Expect(strings.Contains(secretData, "infraProvider: docker")).Should(BeTrue())

Expect(strings.Contains(secretData, "trafficEncapMode: encap")).Should(BeTrue())
Expect(strings.Contains(secretData, "tlsCipherSuites: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_256_GCM_SHA384")).Should(BeTrue())
Expect(strings.Contains(secretData, "AntreaProxy: true")).Should(BeTrue())
Expect(strings.Contains(secretData, "AntreaPolicy: true")).Should(BeTrue())
content := secret.Data["values.yaml"]
spec := antreatype.AntreaConfigSpec{}
err = yaml.Unmarshal(content, &spec)
if err != nil {
return false
}
Expect(spec.Antrea.AntreaConfigDataValue.ServiceCIDR, "192.168.0.0/16").Should(BeTrue())
Expect(spec.Antrea.AntreaConfigDataValue.ServiceCIDRv6, "fd00:100:96::/48").Should(BeTrue())
Expect(spec.InfraProvider, "docker").Should(BeTrue())
Expect(spec.Antrea.AntreaConfigDataValue.TrafficEncapMode, "encap").Should(BeTrue())
Expect(spec.Antrea.AntreaConfigDataValue.TLSCipherSuites, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_256_GCM_SHA384").Should(BeTrue())
Expect(spec.Antrea.AntreaConfigDataValue.FeatureGates.AntreaProxy, true).Should(BeTrue())
Expect(spec.Antrea.AntreaConfigDataValue.FeatureGates.AntreaPolicy, true).Should(BeTrue())

return true
}, waitTimeout, pollingInterval).Should(BeTrue())
Expand Down Expand Up @@ -302,16 +306,19 @@ var _ = Describe("AntreaConfig Reconciler and Webhooks", func() {
Expect(secret.Type).Should(Equal(v1.SecretTypeOpaque))

// check data value secret contents
secretData := string(secret.Data["values.yaml"])

Expect(strings.Contains(secretData, "serviceCIDR: 192.168.0.0/16")).Should(BeTrue())
Expect(strings.Contains(secretData, "serviceCIDRv6: fd00:100:96::/48")).Should(BeTrue())
Expect(strings.Contains(secretData, "infraProvider: vsphere")).Should(BeTrue())

Expect(strings.Contains(secretData, "trafficEncapMode: encap")).Should(BeTrue())
Expect(strings.Contains(secretData, "tlsCipherSuites: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_256_GCM_SHA384")).Should(BeTrue())
Expect(strings.Contains(secretData, "AntreaProxy: true")).Should(BeTrue())
Expect(strings.Contains(secretData, "AntreaPolicy: true")).Should(BeTrue())
content := secret.Data["values.yaml"]
spec := antreatype.AntreaConfigSpec{}
err = yaml.Unmarshal(content, &spec)
if err != nil {
return false
}
Expect(spec.Antrea.AntreaConfigDataValue.ServiceCIDR, "192.168.0.0/16").Should(BeTrue())
Expect(spec.Antrea.AntreaConfigDataValue.ServiceCIDRv6, "fd00:100:96::/48").Should(BeTrue())
Expect(spec.InfraProvider, "vsphere").Should(BeTrue())
Expect(spec.Antrea.AntreaConfigDataValue.TrafficEncapMode, "encap").Should(BeTrue())
Expect(spec.Antrea.AntreaConfigDataValue.TLSCipherSuites, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_256_GCM_SHA384").Should(BeTrue())
Expect(spec.Antrea.AntreaConfigDataValue.FeatureGates.AntreaProxy, true).Should(BeTrue())
Expect(spec.Antrea.AntreaConfigDataValue.FeatureGates.AntreaPolicy, true).Should(BeTrue())

return true
}, waitTimeout, pollingInterval).Should(BeTrue())
Expand Down

0 comments on commit aee41f0

Please sign in to comment.