Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix aks credentials passing to buildUpstreamClusterState() func #174

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controller/aks-cluster-config-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ func (h *Handler) getClusterKubeConfig(ctx context.Context, spec *aksv1.AKSClust
return config, nil
}

func (h *Handler) buildUpstreamClusterState(ctx context.Context, spec *aksv1.AKSClusterConfigSpec) (*aksv1.AKSClusterConfigSpec, error) {
func (h *Handler) buildUpstreamClusterState(ctx context.Context, credentials *aks.Credentials, spec *aksv1.AKSClusterConfigSpec) (*aksv1.AKSClusterConfigSpec, error) {
upstreamSpec := &aksv1.AKSClusterConfigSpec{}

clusterState, err := h.azureClients.clustersClient.Get(ctx, spec.ResourceGroup, spec.ClusterName)
Expand Down
15 changes: 11 additions & 4 deletions controller/aks-cluster-config-handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rancher/aks-operator/pkg/aks"
"github.com/rancher/aks-operator/pkg/aks/services/mock_services"
aksv1 "github.com/rancher/aks-operator/pkg/apis/aks.cattle.io/v1"
aksv1controllers "github.com/rancher/aks-operator/pkg/generated/controllers/aks.cattle.io"
Expand Down Expand Up @@ -749,6 +750,7 @@ var _ = Describe("buildUpstreamClusterState", func() {
handler *Handler
mockController *gomock.Controller
clusterClientMock *mock_services.MockManagedClustersClientInterface
credentials *aks.Credentials
aksConfig *aksv1.AKSClusterConfig
clusterState *containerservice.ManagedCluster
)
Expand All @@ -757,6 +759,11 @@ var _ = Describe("buildUpstreamClusterState", func() {
mockController = gomock.NewController(GinkgoT())
clusterClientMock = mock_services.NewMockManagedClustersClientInterface(mockController)

credentials = &aks.Credentials{
AuthBaseURL: to.StringPtr("test"),
BaseURL: to.StringPtr("test"),
}

aksConfig = &aksv1.AKSClusterConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Expand Down Expand Up @@ -839,7 +846,7 @@ var _ = Describe("buildUpstreamClusterState", func() {
It("should build upstream cluster state", func() {
clusterClientMock.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(*clusterState, nil)

upstreamSpec, err := handler.buildUpstreamClusterState(ctx, &aksConfig.Spec)
upstreamSpec, err := handler.buildUpstreamClusterState(ctx, credentials, &aksConfig.Spec)
Expect(err).NotTo(HaveOccurred())
Expect(upstreamSpec).NotTo(BeNil())

Expand Down Expand Up @@ -884,23 +891,23 @@ var _ = Describe("buildUpstreamClusterState", func() {
It("should fail if azure client fails to get cluster", func() {
clusterClientMock.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(*clusterState, errors.New("error"))

_, err := handler.buildUpstreamClusterState(ctx, &aksConfig.Spec)
_, err := handler.buildUpstreamClusterState(ctx, credentials, &aksConfig.Spec)
Expect(err).To(HaveOccurred())
})

It("should fail if kubernetes version is nil", func() {
clusterState.KubernetesVersion = nil
clusterClientMock.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(*clusterState, nil)

_, err := handler.buildUpstreamClusterState(ctx, &aksConfig.Spec)
_, err := handler.buildUpstreamClusterState(ctx, credentials, &aksConfig.Spec)
Expect(err).To(HaveOccurred())
})

It("should fail if dns prefix is nil", func() {
clusterState.DNSPrefix = nil
clusterClientMock.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(*clusterState, nil)

_, err := handler.buildUpstreamClusterState(ctx, &aksConfig.Spec)
_, err := handler.buildUpstreamClusterState(ctx, credentials, &aksConfig.Spec)
Expect(err).To(HaveOccurred())
})
})
2 changes: 1 addition & 1 deletion controller/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ func BuildUpstreamClusterState(ctx context.Context, secretsCache wranglerv1.Secr
clustersClient: clustersClient,
},
}
return h.buildUpstreamClusterState(ctx, spec)
return h.buildUpstreamClusterState(ctx, credentials, spec)
}