2021-09-06 17:42:15 +03:00
|
|
|
package cluster
|
|
|
|
|
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the Apache License 2.0.
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-08-09 09:53:57 +03:00
|
|
|
"fmt"
|
2021-09-06 17:42:15 +03:00
|
|
|
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
|
|
|
"github.com/Azure/ARO-RP/pkg/api"
|
2021-09-10 14:04:26 +03:00
|
|
|
"github.com/Azure/ARO-RP/pkg/util/arm"
|
|
|
|
"github.com/Azure/ARO-RP/pkg/util/stringutils"
|
2021-09-06 17:42:15 +03:00
|
|
|
)
|
|
|
|
|
2022-01-26 00:10:52 +03:00
|
|
|
// migrateStorageAccounts redeploys storage accounts with firewall rules preventing external access
|
|
|
|
// The encryption flag is set to false/disabled for legacy storage accounts.
|
2021-09-10 14:04:26 +03:00
|
|
|
func (m *manager) migrateStorageAccounts(ctx context.Context) error {
|
|
|
|
resourceGroup := stringutils.LastTokenByte(m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID, '/')
|
2023-10-12 19:53:38 +03:00
|
|
|
ocpSubnets, err := m.subnetsWithServiceEndpoint(ctx, storageServiceEndpoint)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2022-06-07 10:04:16 +03:00
|
|
|
}
|
2023-10-12 19:53:38 +03:00
|
|
|
|
2021-09-10 14:04:26 +03:00
|
|
|
clusterStorageAccountName := "cluster" + m.doc.OpenShiftCluster.Properties.StorageSuffix
|
|
|
|
registryStorageAccountName := m.doc.OpenShiftCluster.Properties.ImageRegistryStorageAccountName
|
|
|
|
|
|
|
|
t := &arm.Template{
|
|
|
|
Schema: "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
|
|
|
|
ContentVersion: "1.0.0.0",
|
|
|
|
Resources: []*arm.Resource{
|
2024-10-09 18:18:05 +03:00
|
|
|
m.storageAccount(clusterStorageAccountName, m.doc.OpenShiftCluster.Location, ocpSubnets, false, true),
|
|
|
|
m.storageAccount(registryStorageAccountName, m.doc.OpenShiftCluster.Location, ocpSubnets, false, false),
|
2021-09-10 14:04:26 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-05-03 05:10:43 +03:00
|
|
|
return arm.DeployTemplate(ctx, m.log, m.deployments, resourceGroup, "storage", t, nil)
|
2021-09-10 14:04:26 +03:00
|
|
|
}
|
|
|
|
|
2021-09-06 17:42:15 +03:00
|
|
|
func (m *manager) populateRegistryStorageAccountName(ctx context.Context) error {
|
|
|
|
if m.doc.OpenShiftCluster.Properties.ImageRegistryStorageAccountName != "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-02-16 17:16:48 +03:00
|
|
|
rc, err := m.imageregistrycli.ImageregistryV1().Configs().Get(ctx, "cluster", metav1.GetOptions{})
|
2021-09-06 17:42:15 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
m.doc, err = m.db.PatchWithLease(ctx, m.doc.Key, func(doc *api.OpenShiftClusterDocument) error {
|
2022-08-04 13:11:43 +03:00
|
|
|
if rc.Spec.Storage.Azure == nil {
|
|
|
|
return fmt.Errorf("azure storage field is nil in image registry config")
|
|
|
|
}
|
|
|
|
|
2021-09-06 17:42:15 +03:00
|
|
|
doc.OpenShiftCluster.Properties.ImageRegistryStorageAccountName = rc.Spec.Storage.Azure.AccountName
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return err
|
|
|
|
}
|