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

Commit

Permalink
add nsx related config into configspec when antreaNsx is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
liu4480 committed Mar 15, 2023
1 parent af1fffa commit 1a3af27
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion addons/controllers/antrea/antreaconfig_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"strings"

"github.com/pkg/errors"

"golang.org/x/mod/semver"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterapiutil "sigs.k8s.io/cluster-api/util"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -284,5 +285,39 @@ func mapAntreaConfigSpec(cluster *clusterv1beta1.Cluster, config *cniv1alpha2.An
configSpec.Antrea.AntreaConfigDataValue.FeatureGates.MultiCluster = &config.Spec.Antrea.AntreaConfigDataValue.FeatureGates.MultiCluster
}

//NSX related
if semver.Compare(version, "1.7.1") >= 0 && config.Spec.AntreaNsx.Enable {
configSpec.AntreaNsx.Enable = config.Spec.AntreaNsx.Enable
if config.Spec.AntreaNsx.BootstrapFrom.Inline != nil {
configSpec.AntreaNsx.BootstrapFrom.Inline.NsxManagers = config.Spec.AntreaNsx.BootstrapFrom.Inline.NsxManagers
configSpec.AntreaNsx.BootstrapFrom.Inline.ClusterName = config.Spec.AntreaNsx.BootstrapFrom.Inline.ClusterName
// NSX cert
secret := &corev1.Secret{}
err = client.Get(context.TODO(), types.NamespacedName{
Namespace: config.Namespace,
Name: config.Name,
}, secret)
if err != nil {
return configSpec, err
}
if secret.Data == nil {
return configSpec, fmt.Errorf("missing secret data")
}
if _, ok := secret.Data["tls.crt"]; !ok {
return configSpec, fmt.Errorf("missing tls.crt")
}
configSpec.AntreaNsx.BootstrapFrom.Inline.NsxCertRef.TLSCert = string(secret.Data["tls.crt"])
if _, ok := secret.Data["tls.key"]; !ok {
return configSpec, fmt.Errorf("missing tls.key")
}
configSpec.AntreaNsx.BootstrapFrom.Inline.NsxCertRef.TLSKey = string(secret.Data["tls.key"])
} else if config.Spec.AntreaNsx.BootstrapFrom.ProviderRef != nil {
configSpec.AntreaNsx.BootstrapFrom.ProviderRef.ApiVersion = config.Spec.AntreaNsx.BootstrapFrom.ProviderRef.ApiGroup
configSpec.AntreaNsx.BootstrapFrom.ProviderRef.Kind = config.Spec.AntreaNsx.BootstrapFrom.ProviderRef.Kind
configSpec.AntreaNsx.BootstrapFrom.ProviderRef.Name = config.Spec.AntreaNsx.BootstrapFrom.ProviderRef.Name
}
configSpec.AntreaNsx.AntreaNsxConfig.InfraType = config.Spec.AntreaNsx.AntreaNsxConfig.InfraType
}

return configSpec, nil
}

0 comments on commit 1a3af27

Please sign in to comment.