Skip to content

Commit 450cdf3

Browse files
Add support for Kusto resources (#4680)
* Add support for Microsoft.Kusto/Cluster * WIP * Allow for mapping Name to AzureName * More WIP * Fix failing test * Add data connection resources * Improve error reporting * Generate deepcopy files * Rename test file * Fix TypeTransformer bug * Remove ReadOnlyFollowingDatabase * Update recording * Add links to samples * Add customizations * Add sample and recording * Fix test generation * Split object vs oneof generators * Include simple properties in oneof * Simplify and fix generated code * Fix test generation * Split object vs oneof generators * Include simple properties in oneof * Simplify and fix generated code * Update generated code * Update generated files * Address PR feedback * Clarified comment --------- Co-authored-by: Harshdeep Singh <38904804+super-harsh@users.noreply.github.com>
1 parent e62f306 commit 450cdf3

File tree

64 files changed

+42954
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+42954
-40
lines changed

docs/hugo/content/reference/_index.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,20 @@ These resource(s) are available for use in the current release of ASO. Different
589589
| [Extension]({{< relref "/reference/kubernetesconfiguration/v1api20230501#Extension" >}}) | 2023-05-01 | v1api20230501 | v2.4.0 | [View](https://github.com/Azure/azure-service-operator/tree/main/v2/samples/kubernetesconfiguration/v1api20230501/v1api20230501_extension.yaml) |
590590
| [FluxConfiguration]({{< relref "/reference/kubernetesconfiguration/v1api20230501#FluxConfiguration" >}}) | 2023-05-01 | v1api20230501 | v2.10.0 | [View](https://github.com/Azure/azure-service-operator/tree/main/v2/samples/kubernetesconfiguration/v1api20230501/v1api20230501_fluxconfiguration.yaml) |
591591

592+
## Kusto
593+
594+
To install the CRDs for these resources, your ASO configuration must include `kusto.azure.com/*` as a one of the configured CRD patterns. See [CRD Management in ASO](https://azure.github.io/azure-service-operator/guide/crd-management/) for details on doing this for both [Helm](https://azure.github.io/azure-service-operator/guide/crd-management/#helm) and [YAML](https://azure.github.io/azure-service-operator/guide/crd-management/#yaml) based installations.
595+
596+
### Next Release
597+
598+
Development of these new resources is complete and they will be available in the next release of ASO.
599+
600+
| Resource | ARM Version | CRD Version | Supported From | Sample |
601+
|----------------|-------------|---------------|----------------|------------------------------------------------------------------------------------------------------------------------------------|
602+
| Cluster | 2023-08-15 | v1api20230815 | v2.13.0 | [View](https://github.com/Azure/azure-service-operator/tree/main/v2/samples/kusto/v1api20230815/v1api20230815_cluster.yaml) |
603+
| DataConnection | 2023-08-15 | v1api20230815 | v2.13.0 | [View](https://github.com/Azure/azure-service-operator/tree/main/v2/samples/kusto/v1api20230815/v1api20230815_dataconnection.yaml) |
604+
| Database | 2023-08-15 | v1api20230815 | v2.13.0 | [View](https://github.com/Azure/azure-service-operator/tree/main/v2/samples/kusto/v1api20230815/v1api20230815_database.yaml) |
605+
592606
## MachineLearningServices
593607

594608
To install the CRDs for these resources, your ASO configuration must include `machinelearningservices.azure.com/*` as a one of the configured CRD patterns. See [CRD Management in ASO](https://azure.github.io/azure-service-operator/guide/crd-management/) for details on doing this for both [Helm](https://azure.github.io/azure-service-operator/guide/crd-management/#helm) and [YAML](https://azure.github.io/azure-service-operator/guide/crd-management/#yaml) based installations.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Kusto Supported Resources
3+
linktitle: Kusto
4+
no_list: true
5+
---
6+
To install the CRDs for these resources, your ASO configuration must include `kusto.azure.com/*` as a one of the configured CRD patterns. See [CRD Management in ASO](https://azure.github.io/azure-service-operator/guide/crd-management/) for details on doing this for both [Helm](https://azure.github.io/azure-service-operator/guide/crd-management/#helm) and [YAML](https://azure.github.io/azure-service-operator/guide/crd-management/#yaml) based installations.
7+
8+
### Next Release
9+
10+
Development of these new resources is complete and they will be available in the next release of ASO.
11+
12+
| Resource | ARM Version | CRD Version | Supported From | Sample |
13+
|----------------|-------------|---------------|----------------|------------------------------------------------------------------------------------------------------------------------------------|
14+
| Cluster | 2023-08-15 | v1api20230815 | v2.13.0 | [View](https://github.com/Azure/azure-service-operator/tree/main/v2/samples/kusto/v1api20230815/v1api20230815_cluster.yaml) |
15+
| DataConnection | 2023-08-15 | v1api20230815 | v2.13.0 | [View](https://github.com/Azure/azure-service-operator/tree/main/v2/samples/kusto/v1api20230815/v1api20230815_dataconnection.yaml) |
16+
| Database | 2023-08-15 | v1api20230815 | v2.13.0 | [View](https://github.com/Azure/azure-service-operator/tree/main/v2/samples/kusto/v1api20230815/v1api20230815_database.yaml) |
17+

v2/api/kusto/customizations/cluster_extension_types_gen.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation.
3+
* Licensed under the MIT license.
4+
*/
5+
6+
package customizations
7+
8+
import (
9+
"context"
10+
"fmt"
11+
"strings"
12+
13+
"github.com/go-logr/logr"
14+
"github.com/rotisserie/eris"
15+
"sigs.k8s.io/controller-runtime/pkg/conversion"
16+
17+
kusto "github.com/Azure/azure-service-operator/v2/api/kusto/v1api20230815/storage"
18+
"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
19+
"github.com/Azure/azure-service-operator/v2/internal/resolver"
20+
"github.com/Azure/azure-service-operator/v2/internal/set"
21+
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
22+
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/extensions"
23+
)
24+
25+
var _ extensions.PreReconciliationChecker = &ClusterExtension{}
26+
27+
// clusterTerminalStates is the set of provisioning states that are considered terminal for a cluster.
28+
// These are all listed lowercase, so we can do a case-insensitive match.
29+
var clusterTerminalStates = set.Make(
30+
"succeeded",
31+
"failed",
32+
"canceled",
33+
)
34+
35+
// PreReconcileCheck is called before the reconciliation of the resource to see if the cluster
36+
// is in a state that will allow reconciliation to proceed.
37+
// If a cluster has a provisioningState not in the set above, it will reject any attempt to PUT a
38+
// new state out of hand; so there's no point in even trying. This is true even if the PUT we're
39+
// doing will have no effect on the state of the cluster.
40+
func (ext *ClusterExtension) PreReconcileCheck(
41+
_ context.Context,
42+
obj genruntime.MetaObject,
43+
_ genruntime.MetaObject,
44+
_ *resolver.Resolver,
45+
_ *genericarmclient.GenericClient,
46+
_ logr.Logger,
47+
_ extensions.PreReconcileCheckFunc,
48+
) (extensions.PreReconcileCheckResult, error) {
49+
// This has to be the current hub storage version. It will need to be updated
50+
// if the hub storage version changes.
51+
cluster, ok := obj.(*kusto.Cluster)
52+
if !ok {
53+
return extensions.PreReconcileCheckResult{},
54+
eris.Errorf("cannot run on unknown resource type %T, expected *kusto.Cluster", obj)
55+
}
56+
57+
// Type assert that we are the hub type. This will fail to compile if
58+
// the hub type has been changed but this extension has not
59+
var _ conversion.Hub = cluster
60+
61+
// If the cluster is in a state that will reject any PUT, then we should skip reconciliation
62+
// as there's no point in even trying.
63+
// This allows us to "play nice with others" and not use up request quota attempting to make changes when we
64+
// already know those attempts will fail.
65+
state := cluster.Status.ProvisioningState
66+
if state != nil && clusterProvisioningStateBlocksReconciliation(state) {
67+
return extensions.BlockReconcile(
68+
fmt.Sprintf("Cluster is in provisioning state %q", *state)),
69+
nil
70+
}
71+
72+
return extensions.ProceedWithReconcile(), nil
73+
}
74+
75+
func clusterProvisioningStateBlocksReconciliation(provisioningState *string) bool {
76+
if provisioningState == nil {
77+
return false
78+
}
79+
80+
return !clusterTerminalStates.Contains(strings.ToLower(*provisioningState))
81+
}

v2/api/kusto/customizations/data_connection_extension_types_gen.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v2/api/kusto/customizations/database_extension_types_gen.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation.
3+
* Licensed under the MIT license.
4+
*/
5+
6+
package customizations
7+
8+
import (
9+
"context"
10+
"fmt"
11+
12+
"github.com/go-logr/logr"
13+
"github.com/rotisserie/eris"
14+
"sigs.k8s.io/controller-runtime/pkg/conversion"
15+
16+
kusto "github.com/Azure/azure-service-operator/v2/api/kusto/v1api20230815/storage"
17+
"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
18+
"github.com/Azure/azure-service-operator/v2/internal/resolver"
19+
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
20+
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/extensions"
21+
)
22+
23+
var _ extensions.PreReconciliationChecker = &ClusterExtension{}
24+
25+
// PreReconcileCheck is called before the reconciliation of the resource to see if the cluster
26+
// is in a state that will allow reconciliation to proceed.
27+
// We can't try to create/update a Database unless the cluster is in a state that allows it.
28+
func (ext *DatabaseExtension) PreReconcileCheck(
29+
_ context.Context,
30+
obj genruntime.MetaObject,
31+
owner genruntime.MetaObject,
32+
_ *resolver.Resolver,
33+
_ *genericarmclient.GenericClient,
34+
_ logr.Logger,
35+
_ extensions.PreReconcileCheckFunc,
36+
) (extensions.PreReconcileCheckResult, error) {
37+
// This has to be the current hub storage version. It will need to be updated
38+
// if the hub storage version changes.
39+
cluster, ok := owner.(*kusto.Cluster)
40+
if !ok {
41+
return extensions.PreReconcileCheckResult{},
42+
eris.Errorf("cannot run on unknown resource type %T, expected owner to be *kusto.Cluster", owner)
43+
}
44+
45+
// Type assert that we are the hub type. This will fail to compile if
46+
// the hub type has been changed but this extension has not
47+
var _ conversion.Hub = cluster
48+
49+
// If our owning *cluster* is in a state that will reject any PUT, then we should skip
50+
// reconciliation of the database as there's no point in even trying.
51+
// One way this can happen is when we reconcile the cluster, putting it into an `Updating`
52+
// state for a period. While it's in that state, we can't even try to reconcile the database as
53+
// the operation will fail with a `Conflict` error.
54+
// Checking the state of our owning cluster allows us to "play nice with others" and not use up
55+
// request quota attempting to make changes when we already know those attempts will fail.
56+
state := cluster.Status.ProvisioningState
57+
if state != nil && clusterProvisioningStateBlocksReconciliation(state) {
58+
return extensions.BlockReconcile(
59+
fmt.Sprintf("Owning cluster is in provisioning state %q", *state)),
60+
nil
61+
}
62+
63+
return extensions.ProceedWithReconcile(), nil
64+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Code generated by azure-service-operator-codegen. DO NOT EDIT.
2+
github.com/Azure/azure-service-operator/v2/api/kusto/customizations
3+
-------------------------------------------------------------------
4+
ClusterExtension: Object (0 properties)
5+
6+
DataConnectionExtension: Object (0 properties)
7+
8+
DatabaseExtension: Object (0 properties)
9+

0 commit comments

Comments
 (0)