Skip to content

Commit

Permalink
fix comments and test
Browse files Browse the repository at this point in the history
  • Loading branch information
jwtty committed Nov 12, 2024
1 parent ad8bfbe commit a21775d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
10 changes: 5 additions & 5 deletions cmd/hub-net-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ func main() {
exitWithErrorFunc()
}
cloudConfig.SetUserAgent("fleet-hub-net-controller-manager")
klog.V(1).InfoS("Cloud config loaded", "cloudConfig", cloudConfig)

_, _, err = initializeAzureTrafficManagerClients(cloudConfig) // profilesClient, endpointsClient, err
_, _, err = initAzureTrafficManagerClients(cloudConfig) // profilesClient, endpointsClient, err
if err != nil {
klog.ErrorS(err, "Unable to create Azure Traffic Manager clients")
exitWithErrorFunc()
Expand All @@ -215,8 +216,8 @@ func main() {
}
}

// initializeAzureTrafficManagerClients initializes the Azure Traffic Manager profiles and endpoints clients.
func initializeAzureTrafficManagerClients(cloudConfig *azure.CloudConfig) (*armtrafficmanager.ProfilesClient, *armtrafficmanager.EndpointsClient, error) {
// initAzureTrafficManagerClients initializes the Azure Traffic Manager profiles and endpoints clients.
func initAzureTrafficManagerClients(cloudConfig *azure.CloudConfig) (*armtrafficmanager.ProfilesClient, *armtrafficmanager.EndpointsClient, error) {
authProvider, err := azclient.NewAuthProvider(&cloudConfig.ARMClientConfig, &cloudConfig.AzureAuthConfig)
if err != nil {
return nil, nil, fmt.Errorf("failed to create Azure auth provider: %w", err)
Expand All @@ -231,8 +232,7 @@ func initializeAzureTrafficManagerClients(cloudConfig *azure.CloudConfig) (*armt
return nil, nil, fmt.Errorf("failed to get default resource client option: %w", err)
}

rateLimitPolicy := ratelimit.NewRateLimitPolicy(cloudConfig.Config)
if rateLimitPolicy != nil {
if rateLimitPolicy := ratelimit.NewRateLimitPolicy(cloudConfig.Config); rateLimitPolicy != nil {
options.ClientOptions.PerCallPolicies = append(options.ClientOptions.PerCallPolicies, rateLimitPolicy)
}

Expand Down
14 changes: 9 additions & 5 deletions cmd/member-net-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ func setupControllersWithManager(ctx context.Context, hubMgr, memberMgr manager.
}

var azurePublicIPAddressClient publicipaddressclient.Interface
var resourceGroupName string
if *enableTrafficManagerFeature {
klog.V(1).InfoS("Traffic manager feature is enabled, loading cloud config and creating azure clients", "cloudConfigFile", *cloudConfigFile)
cloudConfig, err := azure.NewCloudConfigFromFile(*cloudConfigFile)
Expand All @@ -328,12 +329,15 @@ func setupControllersWithManager(ctx context.Context, hubMgr, memberMgr manager.
return err
}
cloudConfig.SetUserAgent("fleet-member-net-controller-manager")
klog.V(1).InfoS("Cloud config loaded", "cloudConfig", cloudConfig)

azurePublicIPAddressClient, err = initializeAzureNetworkClients(cloudConfig)
azurePublicIPAddressClient, err = initAzureNetworkClients(cloudConfig)
if err != nil {
klog.ErrorS(err, "Unable to create Azure Traffic Manager clients")
return err
}

resourceGroupName = cloudConfig.ResourceGroup
}

klog.V(1).InfoS("Create serviceexport reconciler", "enableTrafficManagerFeature", *enableTrafficManagerFeature)
Expand All @@ -344,6 +348,7 @@ func setupControllersWithManager(ctx context.Context, hubMgr, memberMgr manager.
HubNamespace: mcHubNamespace,
Recorder: memberMgr.GetEventRecorderFor(serviceexport.ControllerName),
EnableTrafficManagerFeature: *enableTrafficManagerFeature,
ResourceGroupName: resourceGroupName,
AzurePublicIPAddressClient: azurePublicIPAddressClient,
}).SetupWithManager(memberMgr); err != nil {
klog.ErrorS(err, "Unable to create serviceexport reconciler")
Expand Down Expand Up @@ -389,8 +394,8 @@ func setupControllersWithManager(ctx context.Context, hubMgr, memberMgr manager.
return nil
}

// initializeAzureNetworkClients initializes the Azure network resource clients, currently only publicIPAddressClient.
func initializeAzureNetworkClients(cloudConfig *azure.CloudConfig) (publicipaddressclient.Interface, error) {
// initAzureNetworkClients initializes the Azure network resource clients, currently only publicIPAddressClient.
func initAzureNetworkClients(cloudConfig *azure.CloudConfig) (publicipaddressclient.Interface, error) {
authProvider, err := azclient.NewAuthProvider(&cloudConfig.ARMClientConfig, &cloudConfig.AzureAuthConfig)
if err != nil {
return nil, fmt.Errorf("failed to create Azure auth provider: %w", err)
Expand All @@ -405,8 +410,7 @@ func initializeAzureNetworkClients(cloudConfig *azure.CloudConfig) (publicipaddr
return nil, fmt.Errorf("failed to get default resource client option: %w", err)
}

rateLimitPolicy := ratelimit.NewRateLimitPolicy(cloudConfig.Config)
if rateLimitPolicy != nil {
if rateLimitPolicy := ratelimit.NewRateLimitPolicy(cloudConfig.Config); rateLimitPolicy != nil {
options.ClientOptions.PerCallPolicies = append(options.ClientOptions.PerCallPolicies, rateLimitPolicy)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/hub/membercluster/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var _ = BeforeSuite(func() {
CRDDirectoryPaths: []string{
filepath.Join("..", "..", "..", "..", "config", "crd", "bases"),
// The package name must match with the version of the fleet package in use.
filepath.Join(build.Default.GOPATH, "pkg", "mod", "go.goms.io", "fleet@v0.10.10", "config", "crd", "bases", "cluster.kubernetes-fleet.io_memberclusters.yaml"),
filepath.Join(build.Default.GOPATH, "pkg", "mod", "go.goms.io", "fleet@v0.11.3", "config", "crd", "bases", "cluster.kubernetes-fleet.io_memberclusters.yaml"),
},
ErrorIfCRDPathMissing: true,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var _ = BeforeSuite(func() {
filepath.Join("../../../../../", "config", "crd", "bases"),
// need to make sure the version matches the one in the go.mod
// workaround mentioned in https://github.com/kubernetes-sigs/controller-runtime/issues/1191
filepath.Join(build.Default.GOPATH, "pkg", "mod", "go.goms.io", "fleet@v0.10.10", "config", "crd", "bases"),
filepath.Join(build.Default.GOPATH, "pkg", "mod", "go.goms.io", "fleet@v0.11.3", "config", "crd", "bases"),
},
ErrorIfCRDPathMissing: true,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var _ = BeforeSuite(func() {
CRDDirectoryPaths: []string{
filepath.Join("..", "..", "..", "..", "..", "config", "crd", "bases"),
// The package name must match with the version of the fleet package in use.
filepath.Join(build.Default.GOPATH, "pkg", "mod", "go.goms.io", "fleet@v0.10.10", "config", "crd", "bases"),
filepath.Join(build.Default.GOPATH, "pkg", "mod", "go.goms.io", "fleet@v0.11.3", "config", "crd", "bases"),
},

ErrorIfCRDPathMissing: true,
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fi
kubectl config use-context $HUB_CLUSTER-admin
# need to make sure the version matches the one in the go.mod
# workaround mentioned in https://github.com/kubernetes-sigs/controller-runtime/issues/1191
kubectl apply -f `go env GOPATH`/pkg/mod/go.goms.io/fleet@v0.10.10/config/crd/bases/cluster.kubernetes-fleet.io_internalmemberclusters.yaml
kubectl apply -f `go env GOPATH`/pkg/mod/go.goms.io/fleet@v0.11.3/config/crd/bases/cluster.kubernetes-fleet.io_internalmemberclusters.yaml
kubectl apply -f config/crd/*
helm install hub-net-controller-manager \
./charts/hub-net-controller-manager/ \
Expand Down

0 comments on commit a21775d

Please # to comment.