Skip to content

Commit

Permalink
Fix Rancher integration
Browse files Browse the repository at this point in the history
Module aks-operator is imported by Rancher and functions:
- BuildUpstreamClusterState
- GetClusterKubeConfig
- GetClusterKubeConfig
- CheckLogAnalyticsWorkspaceForMonitoring
have to be public, because they are used by Rancher.

Signed-off-by: Michal Jura <mjura@suse.com>
  • Loading branch information
mjura committed Jan 20, 2023
1 parent cdb1ecb commit de8a7f9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions controller/aks-cluster-config-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (h *Handler) checkAndUpdate(config *aksv1.AKSClusterConfig) (*aksv1.AKSClus
}

logrus.Infof("Checking configuration for cluster [%s]", config.Spec.ClusterName)
upstreamSpec, err := h.buildUpstreamClusterState(ctx, &config.Spec)
upstreamSpec, err := h.BuildUpstreamClusterState(ctx, &config.Spec)
if err != nil {
return config, err
}
Expand Down Expand Up @@ -510,7 +510,7 @@ func (h *Handler) enqueueUpdate(config *aksv1.AKSClusterConfig) (*aksv1.AKSClust
// createCASecret creates a secret containing ca and endpoint. These can be used to create a kubeconfig via
// the go sdk
func (h *Handler) createCASecret(ctx context.Context, config *aksv1.AKSClusterConfig) error {
kubeConfig, err := h.getClusterKubeConfig(ctx, &config.Spec)
kubeConfig, err := h.GetClusterKubeConfig(ctx, &config.Spec)
if err != nil {
return err
}
Expand Down Expand Up @@ -539,7 +539,7 @@ func (h *Handler) createCASecret(ctx context.Context, config *aksv1.AKSClusterCo
return err
}

func (h *Handler) getClusterKubeConfig(ctx context.Context, spec *aksv1.AKSClusterConfigSpec) (restConfig *rest.Config, err error) {
func (h *Handler) GetClusterKubeConfig(ctx context.Context, spec *aksv1.AKSClusterConfigSpec) (restConfig *rest.Config, err error) {
accessProfile, err := h.azureClients.clustersClient.GetAccessProfile(ctx, spec.ResourceGroup, spec.ClusterName, "clusterAdmin")
if err != nil {
return nil, err
Expand All @@ -554,7 +554,7 @@ func (h *Handler) getClusterKubeConfig(ctx context.Context, spec *aksv1.AKSClust

// buildUpstreamClusterState creates an AKSClusterConfigSpec (spec for the AKS cluster state) from the existing
// cluster configuration.
func (h *Handler) buildUpstreamClusterState(ctx context.Context, spec *aksv1.AKSClusterConfigSpec) (*aksv1.AKSClusterConfigSpec, error) {
func (h *Handler) BuildUpstreamClusterState(ctx context.Context, spec *aksv1.AKSClusterConfigSpec) (*aksv1.AKSClusterConfigSpec, error) {
upstreamSpec := &aksv1.AKSClusterConfigSpec{}

clusterState, err := h.azureClients.clustersClient.Get(ctx, spec.ResourceGroup, spec.ClusterName)
Expand Down
2 changes: 1 addition & 1 deletion pkg/aks/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var regionToOmsRegionMap = map[string]string{
"chinanorth2": "chinaeast2",
}

func checkLogAnalyticsWorkspaceForMonitoring(ctx context.Context, client services.WorkplacesClientInterface,
func CheckLogAnalyticsWorkspaceForMonitoring(ctx context.Context, client services.WorkplacesClientInterface,
location string, group string, wsg string, wsn string) (workspaceID string, err error) {

workspaceRegion, ok := regionToOmsRegionMap[location]
Expand Down
10 changes: 5 additions & 5 deletions pkg/aks/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Test_generateUniqueLogWorkspace(t *testing.T) {
}
}

var _ = Describe("checkLogAnalyticsWorkspaceForMonitoring", func() {
var _ = Describe("CheckLogAnalyticsWorkspaceForMonitoring", func() {
var (
workplacesClientMock *mock_services.MockWorkplacesClientInterface
mockController *gomock.Controller
Expand All @@ -54,7 +54,7 @@ var _ = Describe("checkLogAnalyticsWorkspaceForMonitoring", func() {
workplacesClientMock.EXPECT().Get(ctx, workspaceResourceGroup, workspaceName).Return(operationalinsights.Workspace{
ID: &id,
}, nil)
workspaceID, err := checkLogAnalyticsWorkspaceForMonitoring(ctx,
workspaceID, err := CheckLogAnalyticsWorkspaceForMonitoring(ctx,
workplacesClientMock,
"eastus", workspaceResourceGroup, "", workspaceName)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -80,7 +80,7 @@ var _ = Describe("checkLogAnalyticsWorkspaceForMonitoring", func() {
ID: &id,
}, nil)

workspaceID, err := checkLogAnalyticsWorkspaceForMonitoring(ctx,
workspaceID, err := CheckLogAnalyticsWorkspaceForMonitoring(ctx,
workplacesClientMock,
"eastus", workspaceResourceGroup, "", workspaceName)

Expand All @@ -92,7 +92,7 @@ var _ = Describe("checkLogAnalyticsWorkspaceForMonitoring", func() {
workplacesClientMock.EXPECT().Get(ctx, gomock.Any(), gomock.Any()).Return(operationalinsights.Workspace{}, errors.New("not found"))
workplacesClientMock.EXPECT().CreateOrUpdate(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Return(operationalinsights.WorkspacesCreateOrUpdateFuture{}, errors.New("error"))

_, err := checkLogAnalyticsWorkspaceForMonitoring(ctx,
_, err := CheckLogAnalyticsWorkspaceForMonitoring(ctx,
workplacesClientMock,
"eastus", "workspaceResourceGroup", "", "workspaceName")

Expand All @@ -104,7 +104,7 @@ var _ = Describe("checkLogAnalyticsWorkspaceForMonitoring", func() {
workplacesClientMock.EXPECT().CreateOrUpdate(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Return(operationalinsights.WorkspacesCreateOrUpdateFuture{}, nil)
workplacesClientMock.EXPECT().AsyncCreateUpdateResult(gomock.Any()).Return(operationalinsights.Workspace{}, errors.New("error"))

_, err := checkLogAnalyticsWorkspaceForMonitoring(ctx,
_, err := CheckLogAnalyticsWorkspaceForMonitoring(ctx,
workplacesClientMock,
"eastus", "workspaceResourceGroup", "", "workspaceName")

Expand Down
4 changes: 2 additions & 2 deletions pkg/aks/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func GetSecrets(secretsCache wranglerv1.SecretCache, secretClient wranglerv1.Sec
cred.BaseURL = spec.BaseURL

if cred.TenantID == "" {
cred.TenantID, err = getCachedTenantID(secretClient, cred.SubscriptionID, secret)
cred.TenantID, err = GetCachedTenantID(secretClient, cred.SubscriptionID, secret)
if err != nil {
return nil, err
}
Expand All @@ -105,7 +105,7 @@ type secretClient interface {
Update(*v1.Secret) (*v1.Secret, error)
}

func getCachedTenantID(secretClient secretClient, subscriptionID string, secret *v1.Secret) (string, error) {
func GetCachedTenantID(secretClient secretClient, subscriptionID string, secret *v1.Secret) (string, error) {
annotations := secret.GetAnnotations()
tenantAnno, timestamp := annotations[tenantIDAnnotation], annotations[tenantIDTimestampAnnotation]
if tenantAnno != "" && timestamp != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/aks/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func createManagedCluster(ctx context.Context, cred *Credentials, workplacesClie
Enabled: spec.Monitoring,
}

logAnalyticsWorkspaceResourceID, err := checkLogAnalyticsWorkspaceForMonitoring(ctx, workplacesClient,
logAnalyticsWorkspaceResourceID, err := CheckLogAnalyticsWorkspaceForMonitoring(ctx, workplacesClient,
spec.ResourceLocation, spec.ResourceGroup, to.String(spec.LogAnalyticsWorkspaceGroup), to.String(spec.LogAnalyticsWorkspaceName))
if err != nil {
return managedCluster, err
Expand Down

0 comments on commit de8a7f9

Please sign in to comment.