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

Cherry pick PCP-1614 PCP-1615 #96

Merged
merged 4 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
98 changes: 88 additions & 10 deletions azure/scope/managedcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ func NewManagedControlPlaneScope(ctx context.Context, params ManagedControlPlane

// ManagedControlPlaneScope defines the basic context for an actuator to operate upon.
type ManagedControlPlaneScope struct {
Client client.Client
patchHelper *patch.Helper
kubeConfigData []byte
cache *ManagedControlPlaneCache
Client client.Client
patchHelper *patch.Helper
adminKubeConfigData []byte
userKubeConfigData []byte
cache *ManagedControlPlaneCache

AzureClients
Cluster *clusterv1.Cluster
Expand Down Expand Up @@ -413,6 +414,64 @@ func (s *ManagedControlPlaneScope) ManagedClusterAnnotations() map[string]string
return s.ControlPlane.Annotations
}

// IsLocalAcountsDisabled checks if local accounts have been disabled.
func (s *ManagedControlPlaneScope) IsLocalAcountsDisabled() bool {
if s.IsAadEnabled() &&
s.ControlPlane.Spec.DisableLocalAccounts != nil &&
*s.ControlPlane.Spec.DisableLocalAccounts {
return true
}
return false
}

// IsAadEnabled checks if aad is enabled.
func (s *ManagedControlPlaneScope) IsAadEnabled() bool {
if s.ControlPlane.Spec.AADProfile != nil && s.ControlPlane.Spec.AADProfile.Managed {
return true
}
return false
}

// SetAutoUpgradeVersionStatus sets the auto upgrade version in status
func (s *ManagedControlPlaneScope) SetAutoUpgradeVersionStatus(version string) {
s.ControlPlane.Status.AutoUpgradeVersion = version
}

// IsManagedVersionUpgrade checks if auto upgrade profile is set and if the upgradeChannel is of the type patch, stable or rapid.
func (s *ManagedControlPlaneScope) IsManagedVersionUpgrade() bool {
return s.IsPatchAutoUpgrade() || s.IsStableAutoUpgrade() || s.IsRapidAutoUpgrade()
}

// IsAutoUpgradeStable checks if auto upgrade channel is stable.
func (s *ManagedControlPlaneScope) IsStableAutoUpgrade() bool {
if s.ControlPlane.Spec.AutoUpgradeProfile != nil {
if upgradeChannel := s.ControlPlane.Spec.AutoUpgradeProfile.UpgradeChannel; upgradeChannel == infrav1exp.UpgradeChannelStable {
return true
}
}
return false
}

// IsAutoUpgradeStable checks if auto upgrade channel is rapid.
func (s *ManagedControlPlaneScope) IsRapidAutoUpgrade() bool {
if s.ControlPlane.Spec.AutoUpgradeProfile != nil {
if upgradeChannel := s.ControlPlane.Spec.AutoUpgradeProfile.UpgradeChannel; upgradeChannel == infrav1exp.UpgradeChannelRapid {
return true
}
}
return false
}

// IsAutoUpgradeStable checks if auto upgrade channel is patch.
func (s *ManagedControlPlaneScope) IsPatchAutoUpgrade() bool {
if s.ControlPlane.Spec.AutoUpgradeProfile != nil {
if upgradeChannel := s.ControlPlane.Spec.AutoUpgradeProfile.UpgradeChannel; upgradeChannel == infrav1exp.UpgradeChannelPatch {
return true
}
}
return false
}

// ManagedClusterSpec returns the managed cluster spec.
func (s *ManagedControlPlaneScope) ManagedClusterSpec(ctx context.Context) azure.ResourceSpecGetter {
managedClusterSpec := managedclusters.ManagedClusterSpec{
Expand Down Expand Up @@ -477,6 +536,9 @@ func (s *ManagedControlPlaneScope) ManagedClusterSpec(ctx context.Context) azure
EnableAzureRBAC: s.ControlPlane.Spec.AADProfile.Managed,
AdminGroupObjectIDs: s.ControlPlane.Spec.AADProfile.AdminGroupObjectIDs,
}
if s.ControlPlane.Spec.DisableLocalAccounts != nil {
managedClusterSpec.DisableLocalAccounts = s.ControlPlane.Spec.DisableLocalAccounts
}
}

if s.ControlPlane.Spec.AddonProfiles != nil {
Expand Down Expand Up @@ -522,6 +584,12 @@ func (s *ManagedControlPlaneScope) ManagedClusterSpec(ctx context.Context) azure
}
}

if s.ControlPlane.Spec.AutoUpgradeProfile != nil {
managedClusterSpec.AutoUpgradeProfile = &managedclusters.ManagedClusterAutoUpgradeProfile{
UpgradeChannel: s.ControlPlane.Spec.AutoUpgradeProfile.UpgradeChannel,
}
}

return &managedClusterSpec
}

Expand Down Expand Up @@ -573,14 +641,24 @@ func (s *ManagedControlPlaneScope) MakeEmptyKubeConfigSecret() corev1.Secret {
}
}

// GetKubeConfigData returns a []byte that contains kubeconfig.
func (s *ManagedControlPlaneScope) GetKubeConfigData() []byte {
return s.kubeConfigData
// GetAdminKubeConfigData returns admin kubeconfig.
func (s *ManagedControlPlaneScope) GetAdminKubeConfigData() []byte {
return s.adminKubeConfigData
}

// SetAdminKubeConfigData sets adminKubeconfig data.
func (s *ManagedControlPlaneScope) SetAdminKubeConfigData(kubeConfigData []byte) {
s.adminKubeConfigData = kubeConfigData
}

// GetUserKubeConfigData returns user kubeconfig, required when using AAD with AKS cluster.
func (s *ManagedControlPlaneScope) GetUserKubeConfigData() []byte {
return s.userKubeConfigData
}

// SetKubeConfigData sets kubeconfig data.
func (s *ManagedControlPlaneScope) SetKubeConfigData(kubeConfigData []byte) {
s.kubeConfigData = kubeConfigData
// SetUserKubeConfigData sets userKubeconfig data.
func (s *ManagedControlPlaneScope) SetUserKubeConfigData(kubeConfigData []byte) {
s.userKubeConfigData = kubeConfigData
}

// SetLongRunningOperationState will set the future on the AzureManagedControlPlane status to allow the resource to continue
Expand Down
Loading