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

Add table azure_kubernetes_service_version Closes #606 #623

Merged
merged 6 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions azure/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
167 changes: 167 additions & 0 deletions azure/table_azure_kubernetes_service_version.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ParthaI what was the reasoning behind the naming convention of the table?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
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.KeyColumnSlice{
{
Name: "location",
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: "location",
Description: ColumnDescriptionRegion,
Type: proto.ColumnType_STRING,
Transform: transform.FromQual("location"),
},
}),
}
}

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) {
location := d.EqualsQualString("location")
resourceType := d.EqualsQualString("resource_type")
Comment on lines +128 to +129
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not check if location and resourceType parameters are empty or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@misraved, Thank you for catching that.

  • Looking at the list config, the location is required in the WHERE clause for querying this table.
KeyColumns: plugin.KeyColumnSlice{
				{
					Name:    "location",
					Require: plugin.Required,
				},
				{
					Name:    "resource_type",
					Require: plugin.Optional,
				},
			},
  • If we do not provide the location in the WHERE clause, Steampipe will throw an error stating that the location is required for querying this table.
  • On the other hand, the resource_type is optional in the WHERE clause, meaning we can choose to include it or not.
  • If we include the resource_type in the WHERE clause, the API will filter the response based on the specified value. Otherwise, it will return all resource types.

I don't believe we need to perform any empty checks in this case. Thanks again!


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, location, 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
}
87 changes: 87 additions & 0 deletions docs/tables/azure_kubernetes_service_version.md
Original file line number Diff line number Diff line change
@@ -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 need to pass the `location` in the where clause to query this table.

## Examples

### Basic info

```sql
select
name,
id,
type,
orchestrator_type,
orchestrator_version
from
azure_kubernetes_service_version
where
location = 'eastus2';
```

### List major kubernetes versions

```sql
select
name,
id,
orchestrator_type,
orchestrator_version
from
azure_kubernetes_service_version
where
orchestrator_version = 'major'
and
location = 'eastus2';
```

### List kubernetes orchestrator type

```sql
select
name,
id,
type,
orchestrator_type,
is_preview
from
azure_kubernetes_service_version
where
orchestrator_type = 'Kubernetes'
and
location = '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
location = '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
location = 'eastus2';
```