From 4cdfee2bd5f973b9756ec621136390ad3ac7ea2e Mon Sep 17 00:00:00 2001 From: ParthaI Date: Fri, 23 Jun 2023 16:23:04 +0530 Subject: [PATCH 1/6] Add table azure_kubernetes_service_version Closes #606 --- azure/plugin.go | 1 + .../table_azure_kubernetes_service_version.go | 168 ++++++++++++++++++ .../azure_kubernetes_service_version.md | 87 +++++++++ 3 files changed, 256 insertions(+) create mode 100644 azure/table_azure_kubernetes_service_version.go create mode 100644 docs/tables/azure_kubernetes_service_version.md diff --git a/azure/plugin.go b/azure/plugin.go index b561380b..d83f2fdb 100644 --- a/azure/plugin.go +++ b/azure/plugin.go @@ -102,6 +102,7 @@ func Plugin(ctx context.Context) *plugin.Plugin { "azure_key_vault_managed_hardware_security_module": tableAzureKeyVaultManagedHardwareSecurityModule(ctx), "azure_key_vault_secret": tableAzureKeyVaultSecret(ctx), "azure_kubernetes_cluster": tableAzureKubernetesCluster(ctx), + "azure_kubernetes_service_version": tableAzureAKSOrchestractor(ctx), "azure_kusto_cluster": tableAzureKustoCluster(ctx), "azure_lb": tableAzureLoadBalancer(ctx), "azure_lb_backend_address_pool": tableAzureLoadBalancerBackendAddressPool(ctx), diff --git a/azure/table_azure_kubernetes_service_version.go b/azure/table_azure_kubernetes_service_version.go new file mode 100644 index 00000000..a03725dd --- /dev/null +++ b/azure/table_azure_kubernetes_service_version.go @@ -0,0 +1,168 @@ +package azure + +import ( + "context" + + "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2020-09-01/containerservice" + "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" + "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" + + "github.com/turbot/steampipe-plugin-sdk/v5/plugin" +) + +//// TABLE DEFINITION //// + +func tableAzureAKSOrchestractor(_ context.Context) *plugin.Table { + return &plugin.Table{ + Name: "azure_kubernetes_service_version", + Description: "Azure Kubernetes Service Version", + List: &plugin.ListConfig{ + Hydrate: listAKSOrchestractors, + // KeyColumns: plugin.AllColumns([]string{"region", "resource_type"}), + KeyColumns: plugin.KeyColumnSlice{ + { + Name: "region", + Require: plugin.Required, + }, + { + Name: "resource_type", + Require: plugin.Optional, + }, + }, + }, + Columns: azureColumns([]*plugin.Column{ + { + Name: "name", + Type: proto.ColumnType_STRING, + Description: "Name of the orchestrator version profile list result.", + }, + { + Name: "id", + Description: "Id of the orchestrator version profile list result.", + Type: proto.ColumnType_STRING, + Transform: transform.FromGo(), + }, + { + Name: "type", + Description: "Type of the orchestrator version profile list result.", + Type: proto.ColumnType_STRING, + }, + { + Name: "orchestrator_type", + Description: "The orchestrator type.", + Type: proto.ColumnType_STRING, + }, + { + Name: "orchestrator_version", + Description: "Orchestrator version (major, minor, patch).", + Type: proto.ColumnType_STRING, + }, + { + Name: "default", + Description: "Installed by default if version is not specified.", + Type: proto.ColumnType_BOOL, + }, + { + Name: "is_preview", + Description: "Whether Kubernetes version is currently in preview.", + Type: proto.ColumnType_BOOL, + }, + { + Name: "resource_type", + Description: "Whether Kubernetes version is currently in preview.", + Type: proto.ColumnType_STRING, + Transform: transform.FromQual("resource_type"), + }, + { + Name: "upgrades", + Description: "The list of available upgrade versions.", + Type: proto.ColumnType_JSON, + }, + + // Steampipe standard columns + { + Name: "title", + Description: ColumnDescriptionTitle, + Type: proto.ColumnType_STRING, + Transform: transform.FromField("Name"), + }, + { + Name: "akas", + Description: ColumnDescriptionAkas, + Type: proto.ColumnType_JSON, + Transform: transform.FromField("ID").Transform(idToAkas), + }, + + // Azure standard columns + { + Name: "region", + Description: ColumnDescriptionRegion, + Type: proto.ColumnType_STRING, + Transform: transform.FromQual("region"), + }, + }), + } +} + +type OrchestratorInfo struct { + // ID - READ-ONLY; Id of the orchestrator version profile list result. + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; Name of the orchestrator version profile list result. + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; Type of the orchestrator version profile list result. + Type *string `json:"type,omitempty"` + // OrchestratorType - Orchestrator type. + OrchestratorType *string `json:"orchestratorType,omitempty"` + // OrchestratorVersion - Orchestrator version (major, minor, patch). + OrchestratorVersion *string `json:"orchestratorVersion,omitempty"` + // Default - Installed by default if version is not specified. + Default *bool `json:"default,omitempty"` + // IsPreview - Whether Kubernetes version is currently in preview. + IsPreview *bool `json:"isPreview,omitempty"` + // Upgrades - The list of available upgrade versions. + Upgrades *[]containerservice.OrchestratorProfile `json:"upgrades,omitempty"` +} + +//// LIST FUNCTION + +func listAKSOrchestractors(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { + region := d.EqualsQualString("region") + resourceType := d.EqualsQualString("resource_type") + + session, err := GetNewSession(ctx, d, "MANAGEMENT") + if err != nil { + plugin.Logger(ctx).Error("azure_kubernetes_service_version.listAKSOrchestractors", "session_error", err) + return nil, err + } + + subscriptionID := session.SubscriptionID + + containerserviceClient := containerservice.NewContainerServicesClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID) + containerserviceClient.Authorizer = session.Authorizer + + result, err := containerserviceClient.ListOrchestrators(ctx, region, resourceType) + if err != nil { + plugin.Logger(ctx).Error("azure_kubernetes_service_version.listAKSOrchestractors", "api_error", err) + return nil, err + } + + for _, op := range *result.Orchestrators { + d.StreamListItem(ctx, &OrchestratorInfo{ + ID: result.ID, + Name: result.Name, + Type: result.Type, + OrchestratorType: op.OrchestratorType, + OrchestratorVersion: op.OrchestratorVersion, + Default: op.Default, + IsPreview: op.IsPreview, + Upgrades: op.Upgrades, + }) + // Check if context has been cancelled or if the limit has been hit (if specified) + // if there is a limit, it will return the number of rows required to reach this limit + if d.RowsRemaining(ctx) == 0 { + return nil, nil + } + } + + return nil, err +} diff --git a/docs/tables/azure_kubernetes_service_version.md b/docs/tables/azure_kubernetes_service_version.md new file mode 100644 index 00000000..8ba29f7d --- /dev/null +++ b/docs/tables/azure_kubernetes_service_version.md @@ -0,0 +1,87 @@ +# Table: azure_kubernetes_service_version + +Azure AKS (Azure Kubernetes Service) orchestrator is a managed container orchestration service provided by Microsoft Azure. It simplifies the deployment, management, and scaling of containerized applications using Kubernetes. AKS allows you to deploy and manage containerized applications without the need to manage the underlying infrastructure. It provides automated Kubernetes upgrades, built-in monitoring and diagnostics, and seamless integration with other Azure services. AKS enables developers and DevOps teams to focus on application development and deployment, while Azure takes care of the underlying Kubernetes infrastructure. + +**Note:** You must need to pass the `region` in where clause to query this table. + +## Examples + +### Basic info + +```sql +select + name, + id, + type, + orchestrator_type, + orchestrator_version +from + azure_kubernetes_service_version +where + region = 'eastus2'; +``` + +### List major kubernetes versions + +```sql +select + name, + id, + orchestrator_type, + orchestrator_version +from + azure_kubernetes_service_version +where + orchestrator_version = 'major' +and + region = 'eastus2'; +``` + +### List kubernetes orchestrator type + +```sql +select + name, + id, + type, + orchestrator_type, + is_preview +from + azure_kubernetes_service_version +where + orchestrator_type = 'Kubernetes' +and + region = 'eastus2'; +``` + +### List kubernetes versions that are not in preview + +```sql +select + name, + id, + orchestrator_type, + orchestrator_version, + is_preview +from + azure_kubernetes_service_version +where + not is_preview +and + region = 'eastus2'; +``` + +### Get upgrade details of each kubernetes version + +```sql +select + name, + u ->> 'orchestratorType' as orchestrator_type, + u ->> 'orchestratorVersion' as orchestrator_version, + u ->> 'isPreview' as is_preview +from + azure_kubernetes_service_version, + jsonb_array_elements(upgrades) as u +where + region = 'eastus2'; +``` From 5bae866a1df617cfe04022e70bedb2f3c3ede338 Mon Sep 17 00:00:00 2001 From: ParthaI Date: Fri, 23 Jun 2023 16:29:27 +0530 Subject: [PATCH 2/6] renamed the column region to location --- azure/table_azure_kubernetes_service_version.go | 10 +++++----- docs/tables/azure_kubernetes_service_version.md | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/azure/table_azure_kubernetes_service_version.go b/azure/table_azure_kubernetes_service_version.go index a03725dd..5e600179 100644 --- a/azure/table_azure_kubernetes_service_version.go +++ b/azure/table_azure_kubernetes_service_version.go @@ -21,7 +21,7 @@ func tableAzureAKSOrchestractor(_ context.Context) *plugin.Table { // KeyColumns: plugin.AllColumns([]string{"region", "resource_type"}), KeyColumns: plugin.KeyColumnSlice{ { - Name: "region", + Name: "location", Require: plugin.Required, }, { @@ -95,10 +95,10 @@ func tableAzureAKSOrchestractor(_ context.Context) *plugin.Table { // Azure standard columns { - Name: "region", + Name: "location", Description: ColumnDescriptionRegion, Type: proto.ColumnType_STRING, - Transform: transform.FromQual("region"), + Transform: transform.FromQual("location"), }, }), } @@ -126,7 +126,7 @@ type OrchestratorInfo struct { //// LIST FUNCTION func listAKSOrchestractors(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { - region := d.EqualsQualString("region") + location := d.EqualsQualString("location") resourceType := d.EqualsQualString("resource_type") session, err := GetNewSession(ctx, d, "MANAGEMENT") @@ -140,7 +140,7 @@ func listAKSOrchestractors(ctx context.Context, d *plugin.QueryData, _ *plugin.H containerserviceClient := containerservice.NewContainerServicesClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID) containerserviceClient.Authorizer = session.Authorizer - result, err := containerserviceClient.ListOrchestrators(ctx, region, resourceType) + result, err := containerserviceClient.ListOrchestrators(ctx, location, resourceType) if err != nil { plugin.Logger(ctx).Error("azure_kubernetes_service_version.listAKSOrchestractors", "api_error", err) return nil, err diff --git a/docs/tables/azure_kubernetes_service_version.md b/docs/tables/azure_kubernetes_service_version.md index 8ba29f7d..deedd207 100644 --- a/docs/tables/azure_kubernetes_service_version.md +++ b/docs/tables/azure_kubernetes_service_version.md @@ -2,7 +2,7 @@ Azure AKS (Azure Kubernetes Service) orchestrator is a managed container orchestration service provided by Microsoft Azure. It simplifies the deployment, management, and scaling of containerized applications using Kubernetes. AKS allows you to deploy and manage containerized applications without the need to manage the underlying infrastructure. It provides automated Kubernetes upgrades, built-in monitoring and diagnostics, and seamless integration with other Azure services. AKS enables developers and DevOps teams to focus on application development and deployment, while Azure takes care of the underlying Kubernetes infrastructure. -**Note:** You must need to pass the `region` in where clause to query this table. +**Note:** You must need to pass the `location` in where clause to query this table. ## Examples @@ -18,7 +18,7 @@ select from azure_kubernetes_service_version where - region = 'eastus2'; + location = 'eastus2'; ``` ### List major kubernetes versions @@ -34,7 +34,7 @@ from where orchestrator_version = 'major' and - region = 'eastus2'; + location = 'eastus2'; ``` ### List kubernetes orchestrator type @@ -51,7 +51,7 @@ from where orchestrator_type = 'Kubernetes' and - region = 'eastus2'; + location = 'eastus2'; ``` ### List kubernetes versions that are not in preview @@ -68,7 +68,7 @@ from where not is_preview and - region = 'eastus2'; + location = 'eastus2'; ``` ### Get upgrade details of each kubernetes version @@ -83,5 +83,5 @@ from azure_kubernetes_service_version, jsonb_array_elements(upgrades) as u where - region = 'eastus2'; + location = 'eastus2'; ``` From f55f05b4f164d99d2dd2fbc372a7b735d15f18cd Mon Sep 17 00:00:00 2001 From: ParthaI Date: Fri, 23 Jun 2023 16:40:44 +0530 Subject: [PATCH 3/6] Cleaned up the commented code --- azure/table_azure_kubernetes_service_version.go | 1 - 1 file changed, 1 deletion(-) diff --git a/azure/table_azure_kubernetes_service_version.go b/azure/table_azure_kubernetes_service_version.go index 5e600179..0cbab230 100644 --- a/azure/table_azure_kubernetes_service_version.go +++ b/azure/table_azure_kubernetes_service_version.go @@ -18,7 +18,6 @@ func tableAzureAKSOrchestractor(_ context.Context) *plugin.Table { Description: "Azure Kubernetes Service Version", List: &plugin.ListConfig{ Hydrate: listAKSOrchestractors, - // KeyColumns: plugin.AllColumns([]string{"region", "resource_type"}), KeyColumns: plugin.KeyColumnSlice{ { Name: "location", From 193d7974753d4e8599eb53575201324f7d27eaf6 Mon Sep 17 00:00:00 2001 From: ParthaI <47887552+ParthaI@users.noreply.github.com> Date: Wed, 5 Jul 2023 11:21:34 +0530 Subject: [PATCH 4/6] Update table_azure_kubernetes_service_version.go --- azure/table_azure_kubernetes_service_version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure/table_azure_kubernetes_service_version.go b/azure/table_azure_kubernetes_service_version.go index 0cbab230..43c2d3d5 100644 --- a/azure/table_azure_kubernetes_service_version.go +++ b/azure/table_azure_kubernetes_service_version.go @@ -37,7 +37,7 @@ func tableAzureAKSOrchestractor(_ context.Context) *plugin.Table { }, { Name: "id", - Description: "Id of the orchestrator version profile list result.", + Description: "ID of the orchestrator version profile list result.", Type: proto.ColumnType_STRING, Transform: transform.FromGo(), }, From 5172524978b72e0fcd59d08f56ccaa80e0334e67 Mon Sep 17 00:00:00 2001 From: ParthaI <47887552+ParthaI@users.noreply.github.com> Date: Wed, 5 Jul 2023 11:23:25 +0530 Subject: [PATCH 5/6] Update azure_kubernetes_service_version.md --- docs/tables/azure_kubernetes_service_version.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tables/azure_kubernetes_service_version.md b/docs/tables/azure_kubernetes_service_version.md index deedd207..95be7988 100644 --- a/docs/tables/azure_kubernetes_service_version.md +++ b/docs/tables/azure_kubernetes_service_version.md @@ -2,7 +2,7 @@ Azure AKS (Azure Kubernetes Service) orchestrator is a managed container orchestration service provided by Microsoft Azure. It simplifies the deployment, management, and scaling of containerized applications using Kubernetes. AKS allows you to deploy and manage containerized applications without the need to manage the underlying infrastructure. It provides automated Kubernetes upgrades, built-in monitoring and diagnostics, and seamless integration with other Azure services. AKS enables developers and DevOps teams to focus on application development and deployment, while Azure takes care of the underlying Kubernetes infrastructure. -**Note:** You must need to pass the `location` in where clause to query this table. +**Note:** You need to pass the `location` in the where clause to query this table. ## Examples From 801226db4fa92d0e377cb9a6b6ae4cd016d189b6 Mon Sep 17 00:00:00 2001 From: ParthaI <47887552+ParthaI@users.noreply.github.com> Date: Thu, 6 Jul 2023 13:26:43 +0530 Subject: [PATCH 6/6] Update table_azure_kubernetes_service_version.go --- azure/table_azure_kubernetes_service_version.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/azure/table_azure_kubernetes_service_version.go b/azure/table_azure_kubernetes_service_version.go index 43c2d3d5..c49e631f 100644 --- a/azure/table_azure_kubernetes_service_version.go +++ b/azure/table_azure_kubernetes_service_version.go @@ -128,6 +128,11 @@ func listAKSOrchestractors(ctx context.Context, d *plugin.QueryData, _ *plugin.H location := d.EqualsQualString("location") resourceType := d.EqualsQualString("resource_type") + // Empty Check + if location == "" { + return nil, nil + } + session, err := GetNewSession(ctx, d, "MANAGEMENT") if err != nil { plugin.Logger(ctx).Error("azure_kubernetes_service_version.listAKSOrchestractors", "session_error", err)