-
Notifications
You must be signed in to change notification settings - Fork 18
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
Changes from 5 commits
4cdfee2
5bae866
f55f05b
193d797
5172524
801226d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we not check if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @misraved, Thank you for catching that.
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 | ||
} |
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'; | ||
``` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per terraform we have named it like that: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/kubernetes_service_versions