Skip to content
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 3 additions & 10 deletions frontend/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,8 @@ type FrontendOpts struct {
auditLogQueueSize int
auditConnectSocket bool

clustersServiceURL string
clusterServiceProvisionShard string
clusterServiceNoopProvision bool
clusterServiceNoopDeprovision bool
insecure bool
clustersServiceURL string
insecure bool

location string
metricsPort int
Expand Down Expand Up @@ -102,9 +99,6 @@ func NewRootCmd() *cobra.Command {

rootCmd.Flags().StringVar(&opts.clustersServiceURL, "clusters-service-url", "https://api.openshift.com", "URL of the OCM API gateway.")
rootCmd.Flags().BoolVar(&opts.insecure, "insecure", false, "Skip validating TLS for clusters-service.")
rootCmd.Flags().StringVar(&opts.clusterServiceProvisionShard, "cluster-service-provision-shard", "", "Manually specify provision shard for all requests to cluster service")
rootCmd.Flags().BoolVar(&opts.clusterServiceNoopProvision, "cluster-service-noop-provision", false, "Skip cluster service provisioning steps for development purposes")
rootCmd.Flags().BoolVar(&opts.clusterServiceNoopDeprovision, "cluster-service-noop-deprovision", false, "Skip cluster service deprovisioning steps for development purposes")

rootCmd.Flags().BoolVar(&opts.exitOnPanic, "exit-on-panic", opts.exitOnPanic,
"If set, frontend will exit the process if a panic occurs. As of now it only controls the setting of k8s.io/apimachinery/pkg/util/runtime.ReallyCrash",
Expand Down Expand Up @@ -269,8 +263,7 @@ func (opts *FrontendOpts) Run() error {
f := frontend.NewFrontend(
logger, listener, metricsListener,
legacyregistry.Registerer(), legacyregistry.DefaultGatherer,
resourcesDBClient, locksDBClient, csClient, auditClient, opts.location, opts.clusterServiceProvisionShard,
opts.clusterServiceNoopProvision, opts.clusterServiceNoopDeprovision, opts.exitOnPanic,
resourcesDBClient, locksDBClient, csClient, auditClient, opts.location, opts.exitOnPanic,
)

runErrCh := make(chan error, 1)
Expand Down
57 changes: 27 additions & 30 deletions frontend/pkg/frontend/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,32 @@ func (f *Frontend) newClusterAdmissionContext(ctx context.Context, op operation.
OriginalCluster: originalCluster.DeepCopy(),
}

if op.Type == operation.Create {
subscriptionID := originalCluster.ID.SubscriptionID
clusterIterator, err := f.resourcesDBClient.HCPClusters(subscriptionID, "").List(ctx, nil)
if err != nil {
return nil, fmt.Errorf("cannot list clusters for cluster admission: %w", err)
Comment on lines +269 to +273
}
for _, cluster := range clusterIterator.Items(ctx) {
admissionContext.SubscriptionClusters = append(admissionContext.SubscriptionClusters, cluster)

nodePoolIterator, err := f.resourcesDBClient.HCPClusters(subscriptionID, cluster.ID.ResourceGroupName).NodePools(cluster.ID.Name).List(ctx, nil)
if err != nil {
return nil, fmt.Errorf("cannot list node pools for cluster admission: %w", err)
}
for _, nodePool := range nodePoolIterator.Items(ctx) {
admissionContext.SubscriptionNodePools = append(admissionContext.SubscriptionNodePools, nodePool)
}
Comment on lines +275 to +284
if err := nodePoolIterator.GetError(); err != nil {
return nil, fmt.Errorf("cannot list node pools for cluster admission: %w", err)
}
Comment on lines +269 to +287
}
if err := clusterIterator.GetError(); err != nil {
return nil, fmt.Errorf("cannot list clusters for cluster admission: %w", err)
}
return admissionContext, nil
}

if op.Type != operation.Update {
return admissionContext, nil
}
Expand Down Expand Up @@ -364,44 +390,15 @@ func (f *Frontend) createHCPCluster(writer http.ResponseWriter, request *http.Re
}
completeClusterIdentity(newInternalCluster, nil)

var tenantID string
if subscription.Properties != nil && subscription.Properties.TenantId != nil {
tenantID = *subscription.Properties.TenantId
}

initialClusterProperties := map[string]string{}
if len(f.clusterServiceProvisionShard) != 0 {
initialClusterProperties[ocm.CSPropertyProvisionShardID] = f.clusterServiceProvisionShard
}
if f.clusterServiceNoopProvision {
initialClusterProperties[ocm.CSPropertyNoopProvision] = ocm.CSPropertyEnabled
}
if f.clusterServiceNoopDeprovision {
initialClusterProperties[ocm.CSPropertyNoopDeprovision] = ocm.CSPropertyEnabled
}
newClusterServiceClusterBuilder, newClusterServiceAutoscalerBuilder, err := ocm.BuildCSCluster(newInternalCluster.ID, tenantID, newInternalCluster, initialClusterProperties, nil, nil)
if err != nil {
return utils.TrackError(err)
}
logger.Info(fmt.Sprintf("creating resource %s", newInternalCluster.ID))
resultingClusterServiceCluster, err := f.clusterServiceClient.PostCluster(ctx, newClusterServiceClusterBuilder, newClusterServiceAutoscalerBuilder)
if err != nil {
return utils.TrackError(err)
}

csID, err := api.NewInternalID(resultingClusterServiceCluster.HREF())
if err != nil {
return utils.TrackError(err)
}
newInternalCluster.ServiceProviderProperties.ClusterServiceID = &csID

transaction := f.resourcesDBClient.NewTransaction(newInternalCluster.ID.SubscriptionID)

// TODO extract to straight instance creation and then validation.
clusterCreateOperation := database.NewOperation(
database.OperationRequestCreate,
newInternalCluster.ID,
ptr.Deref(newInternalCluster.ServiceProviderProperties.ClusterServiceID, api.InternalID{}),
api.InternalID{},
f.azureLocation,
request.Header.Get(arm.HeaderNameHomeTenantID),
request.Header.Get(arm.HeaderNameClientObjectID),
Expand Down
25 changes: 5 additions & 20 deletions frontend/pkg/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,7 @@ type Frontend struct {
// this is the azure location for this instance of the frontend
azureLocation string

// clusterServiceProvisionShard pins cluster requests to a specific
// Cluster Service provision shard during testing.
clusterServiceProvisionShard string
// clusterServiceNoopProvision short-circuits the full provision flow
// during testing.
clusterServiceNoopProvision bool
// clusterServiceNoopDeprovision short-circuits the full deprovision flow
// during testing.
clusterServiceNoopDeprovision bool
apiRegistry api.APIRegistry
apiRegistry api.APIRegistry

exitOnPanic bool
}
Expand All @@ -94,9 +85,6 @@ func NewFrontend(
csClient ocm.ClusterServiceClientSpec,
auditClient audit.Client,
azureLocation string,
clusterServiceProvisionShard string,
clusterServiceNoopProvision bool,
clusterServiceNoopDeprovision bool,
exitOnPanic bool,
) *Frontend {
// zero side-effect registration path
Expand All @@ -122,13 +110,10 @@ func NewFrontend(
return utils.ContextWithLogger(context.Background(), logger)
},
},
auditClient: auditClient,
resourcesDBClient: resourcesDBClient,
locksDBClient: locksDBClient,
collector: metrics.NewSubscriptionCollector(registerer, resourcesDBClient, azureLocation),
clusterServiceProvisionShard: clusterServiceProvisionShard,
clusterServiceNoopProvision: clusterServiceNoopProvision,
clusterServiceNoopDeprovision: clusterServiceNoopDeprovision,
auditClient: auditClient,
resourcesDBClient: resourcesDBClient,
locksDBClient: locksDBClient,
collector: metrics.NewSubscriptionCollector(registerer, resourcesDBClient, azureLocation),
healthGauge: promauto.With(registerer).NewGauge(
prometheus.GaugeOpts{
Name: healthGaugeName,
Expand Down
31 changes: 25 additions & 6 deletions frontend/pkg/frontend/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestOperationsList(t *testing.T) {
nil,
newNoopAuditClient(t),
api.TestLocation,
"", false, false, true,
true,
)

ctx := utils.ContextWithLogger(t.Context(), testr.New(t))
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestSubscriptionsGET(t *testing.T) {
nil,
newNoopAuditClient(t),
api.TestLocation,
"", false, false, true,
true,
)

// Pre-populate subscription in the mock database
Expand Down Expand Up @@ -349,7 +349,7 @@ func TestSubscriptionsPUT(t *testing.T) {
nil,
newNoopAuditClient(t),
api.TestLocation,
"", false, false, true,
true,
)

body, err := json.Marshal(&test.subscription)
Expand Down Expand Up @@ -436,6 +436,22 @@ func TestDeploymentPreflight(t *testing.T) {
"subnetId": api.TestSubnetResourceID,
"networkSecurityGroupId": api.TestNetworkSecurityGroupResourceID,
},
"etcd": map[string]any{
"dataEncryption": map[string]any{
"keyManagementMode": "CustomerManaged",
"customerManaged": map[string]any{
"encryptionType": "KMS",
"kms": map[string]any{
"visibility": "Public",
"activeKey": map[string]any{
"name": "test-key",
"vaultName": "test-vault",
"version": "test-version",
},
},
},
},
},
},
},
expectStatus: arm.DeploymentPreflightStatusSucceeded,
Expand Down Expand Up @@ -476,6 +492,9 @@ func TestDeploymentPreflight(t *testing.T) {
{message: "Unsupported value: \"invisible\": supported values: \"Private\", \"Public\"", target: "properties.api.visibility"},
{message: "Required value", target: "properties.platform.subnetId"},
{message: "Required value", target: "properties.platform.networkSecurityGroupId"},
{message: "Unsupported value: \"PlatformManaged\": supported values: \"CustomerManaged\"", target: "properties.etcd.dataEncryption.keyManagementMode"},
{message: "Required value", target: "properties.platform.subnetId"},
{message: "Required value", target: "properties.platform.networkSecurityGroupId"},
},
},
{
Expand Down Expand Up @@ -569,7 +588,7 @@ func TestDeploymentPreflight(t *testing.T) {
nil,
newNoopAuditClient(t),
api.TestLocation,
"", false, false, true,
true,
)

subs := map[string]*arm.Subscription{
Expand Down Expand Up @@ -695,7 +714,7 @@ func TestRequestAdminCredential(t *testing.T) {
nil,
newNoopAuditClient(t),
api.TestLocation,
"", false, false, true,
true,
)

// Pre-populate the mock database with cluster and subscription
Expand Down Expand Up @@ -810,7 +829,7 @@ func TestRevokeCredentials(t *testing.T) {
nil,
newNoopAuditClient(t),
api.TestLocation,
"", false, false, true,
true,
)

// Pre-populate the mock database with cluster
Expand Down
2 changes: 1 addition & 1 deletion frontend/pkg/frontend/testhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewTestFrontend(t *testing.T) *Frontend {
nil,
newNoopAuditClient(t),
api.TestLocation,
"", false, false, true,
true,
)
return f
}
Loading
Loading