From d50338a31424cab06d3cba33c0843aaceba29373 Mon Sep 17 00:00:00 2001 From: fraliv13 <5892139+fraliv13@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:11:25 +0200 Subject: [PATCH 1/5] Azure PowerShell Deployment Script --- ...g.totalsoft.ro_azurepowershellscripts.yaml | 171 ++++++++++++++ .../provisioning.totalsoft.ro_entrausers.yaml | 4 +- .../pulumi/azure_powershell_script.go | 71 ++++++ .../provisioners/pulumi/pulumi.go | 14 +- .../provisioning/provisioning_controller.go | 58 +++-- .../provisioning/provisioning_types.go | 17 +- .../v1alpha1/azurePowershelScriptTypes.go | 68 ++++++ pkg/apis/provisioning/v1alpha1/commonTypes.go | 13 +- .../provisioning/v1alpha1/entraUserTypes.go | 1 + pkg/apis/provisioning/v1alpha1/register.go | 2 + .../v1alpha1/zz_generated.deepcopy.go | 99 +++++++++ .../v1alpha1/azurepowershellscript.go | 210 ++++++++++++++++++ .../azurepowershellscriptexportsspec.go | 48 ++++ .../v1alpha1/azurepowershellscriptspec.go | 136 ++++++++++++ pkg/generated/applyconfiguration/utils.go | 6 + .../v1alpha1/azurepowershellscript.go | 208 +++++++++++++++++ .../fake/fake_azurepowershellscript.go | 154 +++++++++++++ .../v1alpha1/fake/fake_provisioning_client.go | 4 + .../v1alpha1/generated_expansion.go | 2 + .../v1alpha1/provisioning_client.go | 5 + .../informers/externalversions/generic.go | 2 + .../v1alpha1/azurepowershellscript.go | 90 ++++++++ .../provisioning/v1alpha1/interface.go | 7 + .../v1alpha1/azurepowershellscript.go | 99 +++++++++ .../v1alpha1/expansion_generated.go | 8 + 25 files changed, 1457 insertions(+), 40 deletions(-) create mode 100644 helm/crds/provisioning.totalsoft.ro_azurepowershellscripts.yaml create mode 100644 internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script.go create mode 100644 pkg/apis/provisioning/v1alpha1/azurePowershelScriptTypes.go create mode 100644 pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscript.go create mode 100644 pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscriptexportsspec.go create mode 100644 pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscriptspec.go create mode 100644 pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/azurepowershellscript.go create mode 100644 pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/fake/fake_azurepowershellscript.go create mode 100644 pkg/generated/informers/externalversions/provisioning/v1alpha1/azurepowershellscript.go create mode 100644 pkg/generated/listers/provisioning/v1alpha1/azurepowershellscript.go diff --git a/helm/crds/provisioning.totalsoft.ro_azurepowershellscripts.yaml b/helm/crds/provisioning.totalsoft.ro_azurepowershellscripts.yaml new file mode 100644 index 0000000..b6d2d0d --- /dev/null +++ b/helm/crds/provisioning.totalsoft.ro_azurepowershellscripts.yaml @@ -0,0 +1,171 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: azurepowershellscripts.provisioning.totalsoft.ro +spec: + group: provisioning.totalsoft.ro + names: + kind: AzurePowerShellScript + listKind: AzurePowerShellScriptList + plural: azurepowershellscripts + singular: azurepowershellscript + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .spec.platformRef + name: Platform + type: string + - jsonPath: .spec.domainRef + name: Domain + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + properties: + dependsOn: + description: List of dependencies + items: + properties: + kind: + description: Kind is a string value representing the REST resource + this dependency represents. + type: string + name: + description: ' The name of the dependency.' + type: string + required: + - kind + - name + type: object + type: array + domainRef: + description: Business Domain that this resource is provision for. + type: string + exports: + description: Export provisioning values spec. + items: + properties: + domain: + description: The domain or bounded-context in which this script + will be used. + type: string + scriptOutputs: + description: Represents the outputs of the Azure PowerShell + script. + properties: + toConfigMap: + properties: + keyTemplate: + type: string + required: + - keyTemplate + type: object + toVault: + properties: + keyTemplate: + type: string + required: + - keyTemplate + type: object + type: object + type: object + type: array + forceUpdateTag: + description: Change value to force the script to execute even if it + has not changed. + type: string + managedIdentity: + description: Represents the managed identity used to run the Azure + PowerShell. + type: string + platformRef: + description: Target platform (custom resource name). + type: string + scriptArguments: + description: |- + Represents the arguments to be passed to the PowerShell script. + eg: "-name JohnDoe" + type: string + scriptContent: + description: ScriptContent represents the content of an Azure PowerShell + script. + type: string + target: + default: + category: Tenant + description: The provisioning target. + properties: + category: + default: Tenant + description: 'Provisioning target type. Possible values: Tenant, + Platform' + enum: + - Tenant + - Platform + type: string + filter: + description: |- + Filter targets (applies for category "Tenant"). + If ommited all targets are selected. + properties: + kind: + default: Blacklist + description: 'Includes or excludes the speciffied targets. + Possibile values: Blacklist, Whitelist' + enum: + - Blacklist + - Whitelist + type: string + values: + description: A list of targets to include or exculde + items: + type: string + type: array + required: + - kind + type: object + required: + - category + type: object + tenantOverrides: + additionalProperties: + x-kubernetes-preserve-unknown-fields: true + description: |- + Overrides for tenants. Dictionary with tenant name as key, spec override as value. + The spec override has the same structure as Spec + type: object + required: + - domainRef + - managedIdentity + - platformRef + - scriptContent + - target + type: object + required: + - spec + type: object + served: true + storage: true + subresources: {} diff --git a/helm/crds/provisioning.totalsoft.ro_entrausers.yaml b/helm/crds/provisioning.totalsoft.ro_entrausers.yaml index 283bd58..13f3f05 100644 --- a/helm/crds/provisioning.totalsoft.ro_entrausers.yaml +++ b/helm/crds/provisioning.totalsoft.ro_entrausers.yaml @@ -78,7 +78,7 @@ spec: items: properties: domain: - description: The domain or bounded-context in which this database + description: The domain or bounded-context in which this user will be used. type: string initialPassword: @@ -117,8 +117,6 @@ spec: - keyTemplate type: object type: object - required: - - domain type: object type: array initialPassword: diff --git a/internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script.go b/internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script.go new file mode 100644 index 0000000..79acaee --- /dev/null +++ b/internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script.go @@ -0,0 +1,71 @@ +package pulumi + +import ( + "encoding/json" + + "github.com/pulumi/pulumi-azure-native-sdk/resources/v2" + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" + "totalsoft.ro/platform-controllers/internal/controllers/provisioning" + "totalsoft.ro/platform-controllers/internal/template" + provisioningv1 "totalsoft.ro/platform-controllers/pkg/apis/provisioning/v1alpha1" +) + +func deployAzurePowerShellScript(target provisioning.ProvisioningTarget, + resourceGroupName pulumi.StringOutput, + azurePowerShellScript *provisioningv1.AzurePowerShellScript, + dependencies []pulumi.Resource, + ctx *pulumi.Context) (*resources.AzurePowerShellScript, error) { + + valueExporter := handleValueExport(target) + gvk := provisioningv1.SchemeGroupVersion.WithKind("AzurePowerShellScript") + + tc := provisioning.GetTemplateContext(target) + + parsedArgs, err := template.ParseTemplate(azurePowerShellScript.Spec.ScriptArguments, tc) + if err != nil { + return nil, err + } + + script, err := resources.NewAzurePowerShellScript(ctx, azurePowerShellScript.Name, &resources.AzurePowerShellScriptArgs{ + Kind: pulumi.String("AzurePowerShell"), + ForceUpdateTag: pulumi.String(azurePowerShellScript.Spec.ForceUpdateTag), // Change to force redeploying the script if desired + ResourceGroupName: resourceGroupName, + Arguments: pulumi.String(parsedArgs), // Set the arguments for the script'"), + ScriptContent: pulumi.String(azurePowerShellScript.Spec.ScriptContent), + CleanupPreference: pulumi.String("OnSuccess"), // Set the cleanup preference for the script + Timeout: pulumi.String("PT1H"), // Set an appropriate timeout for the script + Identity: &resources.ManagedServiceIdentityArgs{ + Type: pulumi.String(resources.ManagedServiceIdentityTypeUserAssigned), + UserAssignedIdentities: pulumi.StringArray{ + pulumi.String(azurePowerShellScript.Spec.ManagedIdentity), + }, + }, + AzPowerShellVersion: pulumi.String("11.0"), // Specify the desired version of Az PowerShell module + RetentionInterval: pulumi.String("P1D"), // Set the retention time for the script's logs + }) + if err != nil { + return nil, err + } + + for _, exp := range azurePowerShellScript.Spec.Exports { + domain := exp.Domain + if domain == "" { + domain = azurePowerShellScript.Spec.DomainRef + } + + err = valueExporter(newExportContext(ctx, domain, azurePowerShellScript.Name, azurePowerShellScript.ObjectMeta, gvk), + + map[string]exportTemplateWithValue{"scriptOutputs": {exp.ScriptOutputs, script.Outputs.ApplyT(func(outputs map[string]interface{}) (string, error) { + outputsJson, err := json.Marshal(outputs) + if err != nil { + return "", err + } + + return string(outputsJson), err + }).(pulumi.StringOutput)}}) + if err != nil { + return nil, err + } + } + return script, nil +} diff --git a/internal/controllers/provisioning/provisioners/pulumi/pulumi.go b/internal/controllers/provisioning/provisioners/pulumi/pulumi.go index 4370e06..5f75deb 100644 --- a/internal/controllers/provisioning/provisioners/pulumi/pulumi.go +++ b/internal/controllers/provisioning/provisioners/pulumi/pulumi.go @@ -37,13 +37,14 @@ func Create(target provisioning.ProvisioningTarget, domain string, infra *provis anyAzureDb := len(infra.AzureDbs) > 0 anyManagedAzureDb := len(infra.AzureManagedDbs) > 0 + anyAzurePowerShellScript := len(infra.AzurePowerShellScripts) > 0 anyHelmRelease := len(infra.HelmReleases) > 0 anyVirtualMachine := len(infra.AzureVirtualMachines) > 0 anyVirtualDesktop := len(infra.AzureVirtualDesktops) > 0 anyEntraUser := len(infra.EntraUsers) > 0 - anyResource := anyAzureDb || anyManagedAzureDb || anyHelmRelease || anyVirtualMachine || anyVirtualDesktop || anyEntraUser - needsResourceGroup := anyVirtualMachine || anyVirtualDesktop + anyResource := anyAzureDb || anyManagedAzureDb || anyHelmRelease || anyVirtualMachine || anyVirtualDesktop || anyEntraUser || anyAzurePowerShellScript + needsResourceGroup := anyVirtualMachine || anyVirtualDesktop || anyAzurePowerShellScript stackName := provisioning.Match(target, func(tenant *platformv1.Tenant) string { @@ -229,6 +230,8 @@ func deployResource(target provisioning.ProvisioningTarget, return deployAzureDb(target, res.(*provisioningv1.AzureDatabase), dependencies, ctx) case string(provisioningv1.ProvisioningResourceKindAzureManagedDatabase): return deployAzureManagedDb(target, res.(*provisioningv1.AzureManagedDatabase), dependencies, ctx) + case string(provisioningv1.ProvisioningResourceKindAzurePowerShellScript): + return deployAzurePowerShellScript(target, *rgName, res.(*provisioningv1.AzurePowerShellScript), dependencies, ctx) case string(provisioningv1.ProvisioningResourceKindHelmRelease): return deployHelmRelease(target, res.(*provisioningv1.HelmRelease), dependencies, ctx) case string(provisioningv1.ProvisioningResourceKindAzureVirtualMachine): @@ -308,6 +311,13 @@ func deployFunc(target provisioning.ProvisioningTarget, domain string, } } + for _, db := range infra.AzurePowerShellScripts { + _, err := deployResourceWithDeps(target, rgName, db, provisionedRes, infra, ctx) + if err != nil { + return err + } + } + for _, hr := range infra.HelmReleases { _, err := deployResourceWithDeps(target, rgName, hr, provisionedRes, infra, ctx) if err != nil { diff --git a/internal/controllers/provisioning/provisioning_controller.go b/internal/controllers/provisioning/provisioning_controller.go index 761e1be..62d0231 100644 --- a/internal/controllers/provisioning/provisioning_controller.go +++ b/internal/controllers/provisioning/provisioning_controller.go @@ -63,14 +63,15 @@ type ProvisioningController struct { provisioner CreateInfrastructureFunc - platformInformer platformInformersv1.PlatformInformer - tenantInformer platformInformersv1.TenantInformer - azureDbInformer provisioningInformersv1.AzureDatabaseInformer - azureManagedDbInformer provisioningInformersv1.AzureManagedDatabaseInformer - helmReleaseInformer provisioningInformersv1.HelmReleaseInformer - azureVirtualMachineInformer provisioningInformersv1.AzureVirtualMachineInformer - azureVirtualDesktopInformer provisioningInformersv1.AzureVirtualDesktopInformer - entraUserInformer provisioningInformersv1.EntraUserInformer + platformInformer platformInformersv1.PlatformInformer + tenantInformer platformInformersv1.TenantInformer + azureDbInformer provisioningInformersv1.AzureDatabaseInformer + azureManagedDbInformer provisioningInformersv1.AzureManagedDatabaseInformer + azurePowerShellScriptInformer provisioningInformersv1.AzurePowerShellScriptInformer + helmReleaseInformer provisioningInformersv1.HelmReleaseInformer + azureVirtualMachineInformer provisioningInformersv1.AzureVirtualMachineInformer + azureVirtualDesktopInformer provisioningInformersv1.AzureVirtualDesktopInformer + entraUserInformer provisioningInformersv1.EntraUserInformer messagingPublisher messaging.MessagingPublisher } @@ -94,14 +95,15 @@ func NewProvisioningController(clientSet clientset.Interface, recorder: &record.FakeRecorder{}, factory: factory, - platformInformer: factory.Platform().V1alpha1().Platforms(), - tenantInformer: factory.Platform().V1alpha1().Tenants(), - azureDbInformer: factory.Provisioning().V1alpha1().AzureDatabases(), - azureManagedDbInformer: factory.Provisioning().V1alpha1().AzureManagedDatabases(), - helmReleaseInformer: factory.Provisioning().V1alpha1().HelmReleases(), - azureVirtualMachineInformer: factory.Provisioning().V1alpha1().AzureVirtualMachines(), - azureVirtualDesktopInformer: factory.Provisioning().V1alpha1().AzureVirtualDesktops(), - entraUserInformer: factory.Provisioning().V1alpha1().EntraUsers(), + platformInformer: factory.Platform().V1alpha1().Platforms(), + tenantInformer: factory.Platform().V1alpha1().Tenants(), + azureDbInformer: factory.Provisioning().V1alpha1().AzureDatabases(), + azureManagedDbInformer: factory.Provisioning().V1alpha1().AzureManagedDatabases(), + azurePowerShellScriptInformer: factory.Provisioning().V1alpha1().AzurePowerShellScripts(), + helmReleaseInformer: factory.Provisioning().V1alpha1().HelmReleases(), + azureVirtualMachineInformer: factory.Provisioning().V1alpha1().AzureVirtualMachines(), + azureVirtualDesktopInformer: factory.Provisioning().V1alpha1().AzureVirtualDesktops(), + entraUserInformer: factory.Provisioning().V1alpha1().EntraUsers(), provisioner: tenantProvisioner, clientset: clientSet, @@ -118,6 +120,7 @@ func NewProvisioningController(clientSet clientset.Interface, addResourceHandlers[*provisioningv1.AzureDatabase]("Azure database", c.azureDbInformer.Informer(), c.enqueueDomain) addResourceHandlers[*provisioningv1.AzureManagedDatabase]("Azure managed database", c.azureManagedDbInformer.Informer(), c.enqueueDomain) + addResourceHandlers[*provisioningv1.AzurePowerShellScript]("Azure PowerShell script", c.azurePowerShellScriptInformer.Informer(), c.enqueueDomain) addResourceHandlers[*provisioningv1.HelmRelease]("Helm release", c.helmReleaseInformer.Informer(), c.enqueueDomain) addResourceHandlers[*provisioningv1.AzureVirtualMachine]("Azure virtual machine", c.azureVirtualMachineInformer.Informer(), c.enqueueDomain) addResourceHandlers[*provisioningv1.AzureVirtualDesktop]("Azure virtual Desktop", c.azureVirtualDesktopInformer.Informer(), c.enqueueDomain) @@ -298,6 +301,16 @@ func (c *ProvisioningController) syncTarget(target ProvisioningTarget, domain st return err } + azurePowerShellScripts, err := c.azurePowerShellScriptInformer.Lister().List(labels.Everything()) + if err != nil { + return err + } + azurePowerShellScripts = selectItemsInTarget(target.GetPlatformName(), domain, azurePowerShellScripts, target) + azurePowerShellScripts, err = applyTargetOverrides(azurePowerShellScripts, target) + if err != nil { + return err + } + helmReleases, err := c.helmReleaseInformer.Lister().List(labels.Everything()) if err != nil { return err @@ -339,12 +352,13 @@ func (c *ProvisioningController) syncTarget(target ProvisioningTarget, domain st } result := c.provisioner(target, domain, &InfrastructureManifests{ - AzureDbs: azureDbs, - AzureManagedDbs: azureManagedDbs, - HelmReleases: helmReleases, - AzureVirtualMachines: azureVirtualMachines, - AzureVirtualDesktops: azureVirtualDesktops, - EntraUsers: entraUsers, + AzureDbs: azureDbs, + AzureManagedDbs: azureManagedDbs, + AzurePowerShellScripts: azurePowerShellScripts, + HelmReleases: helmReleases, + AzureVirtualMachines: azureVirtualMachines, + AzureVirtualDesktops: azureVirtualDesktops, + EntraUsers: entraUsers, }) if result.Error == nil && result.HasChanges { diff --git a/internal/controllers/provisioning/provisioning_types.go b/internal/controllers/provisioning/provisioning_types.go index ce88818..046fea1 100644 --- a/internal/controllers/provisioning/provisioning_types.go +++ b/internal/controllers/provisioning/provisioning_types.go @@ -20,12 +20,13 @@ type CreateInfrastructureFunc func( infra *InfrastructureManifests) ProvisioningResult type InfrastructureManifests struct { - EntraUsers []*provisioningv1.EntraUser - AzureDbs []*provisioningv1.AzureDatabase - AzureManagedDbs []*provisioningv1.AzureManagedDatabase - HelmReleases []*provisioningv1.HelmRelease - AzureVirtualMachines []*provisioningv1.AzureVirtualMachine - AzureVirtualDesktops []*provisioningv1.AzureVirtualDesktop + EntraUsers []*provisioningv1.EntraUser + AzureDbs []*provisioningv1.AzureDatabase + AzureManagedDbs []*provisioningv1.AzureManagedDatabase + AzurePowerShellScripts []*provisioningv1.AzurePowerShellScript + HelmReleases []*provisioningv1.HelmRelease + AzureVirtualMachines []*provisioningv1.AzureVirtualMachine + AzureVirtualDesktops []*provisioningv1.AzureVirtualDesktop } func (infra *InfrastructureManifests) Get(id provisioningv1.ProvisioningResourceIdendtifier) (BaseProvisioningResource, bool) { @@ -36,6 +37,8 @@ func (infra *InfrastructureManifests) Get(id provisioningv1.ProvisioningResource return FindByName[*provisioningv1.AzureDatabase](id.Name, infra.AzureDbs) case provisioningv1.ProvisioningResourceKindAzureManagedDatabase: return FindByName[*provisioningv1.AzureManagedDatabase](id.Name, infra.AzureManagedDbs) + case provisioningv1.ProvisioningResourceKindAzurePowerShellScript: + return FindByName[*provisioningv1.AzurePowerShellScript](id.Name, infra.AzurePowerShellScripts) case provisioningv1.ProvisioningResourceKindHelmRelease: return FindByName[*provisioningv1.HelmRelease](id.Name, infra.HelmReleases) case provisioningv1.ProvisioningResourceKindAzureVirtualMachine: @@ -62,7 +65,7 @@ type ProvisioningResult struct { } type ProvisioningResource interface { - *provisioningv1.EntraUser | *provisioningv1.AzureDatabase | *provisioningv1.AzureManagedDatabase | *provisioningv1.HelmRelease | *provisioningv1.AzureVirtualMachine | *provisioningv1.AzureVirtualDesktop + *provisioningv1.EntraUser | *provisioningv1.AzureDatabase | *provisioningv1.AzureManagedDatabase | *provisioningv1.AzurePowerShellScript | *provisioningv1.HelmRelease | *provisioningv1.AzureVirtualMachine | *provisioningv1.AzureVirtualDesktop GetProvisioningMeta() *provisioningv1.ProvisioningMeta GetSpec() any diff --git a/pkg/apis/provisioning/v1alpha1/azurePowershelScriptTypes.go b/pkg/apis/provisioning/v1alpha1/azurePowershelScriptTypes.go new file mode 100644 index 0000000..ac7ee5f --- /dev/null +++ b/pkg/apis/provisioning/v1alpha1/azurePowershelScriptTypes.go @@ -0,0 +1,68 @@ +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +kubebuilder:printcolumn:name="Platform",type=string,JSONPath=`.spec.platformRef` +// +kubebuilder:printcolumn:name="Domain",type=string,JSONPath=`.spec.domainRef` + +type AzurePowerShellScript struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec AzurePowerShellScriptSpec `json:"spec"` +} + +type AzurePowerShellScriptSpec struct { + + // ScriptContent represents the content of an Azure PowerShell script. + ScriptContent string `json:"scriptContent"` + + // Represents the arguments to be passed to the PowerShell script. + // eg: "-name JohnDoe" + // +optional + ScriptArguments string `json:"scriptArguments,omitempty"` + + // +optional + // Change value to force the script to execute even if it has not changed. + ForceUpdateTag string `json:"forceUpdateTag,omitempty"` + + // Represents the managed identity used to run the Azure PowerShell. + ManagedIdentity string `json:"managedIdentity"` + + // Export provisioning values spec. + // +optional + Exports []AzurePowerShellScriptExportsSpec `json:"exports,omitempty"` + ProvisioningMeta `json:",inline"` +} + +type AzurePowerShellScriptExportsSpec struct { + + // The domain or bounded-context in which this script will be used. + // +optional + Domain string `json:"domain"` + + // Represents the outputs of the Azure PowerShell script. + // +optional + ScriptOutputs ValueExport `json:"scriptOutputs,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type AzurePowerShellScriptList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []AzurePowerShellScript `json:"items"` +} + +func (db *AzurePowerShellScript) GetProvisioningMeta() *ProvisioningMeta { + return &db.Spec.ProvisioningMeta +} + +func (db *AzurePowerShellScript) GetSpec() any { + return &db.Spec +} diff --git a/pkg/apis/provisioning/v1alpha1/commonTypes.go b/pkg/apis/provisioning/v1alpha1/commonTypes.go index ea4b61d..16392e7 100644 --- a/pkg/apis/provisioning/v1alpha1/commonTypes.go +++ b/pkg/apis/provisioning/v1alpha1/commonTypes.go @@ -84,10 +84,11 @@ type ProvisioningResourceIdendtifier struct { type ProvisioningResourceKind string const ( - ProvisioningResourceKindEntraUser = ProvisioningResourceKind("EntraUser") - ProvisioningResourceKindAzureDatabase = ProvisioningResourceKind("AzureDatabase") - ProvisioningResourceKindAzureManagedDatabase = ProvisioningResourceKind("AzureManagedDatabase") - ProvisioningResourceKindAzureVirtualDesktop = ProvisioningResourceKind("AzureVirtualDesktop") - ProvisioningResourceKindAzureVirtualMachine = ProvisioningResourceKind("AzureVirtualMachine") - ProvisioningResourceKindHelmRelease = ProvisioningResourceKind("HelmRelease") + ProvisioningResourceKindEntraUser = ProvisioningResourceKind("EntraUser") + ProvisioningResourceKindAzureDatabase = ProvisioningResourceKind("AzureDatabase") + ProvisioningResourceKindAzureManagedDatabase = ProvisioningResourceKind("AzureManagedDatabase") + ProvisioningResourceKindAzurePowerShellScript = ProvisioningResourceKind("AzurePowerShellScript") + ProvisioningResourceKindAzureVirtualDesktop = ProvisioningResourceKind("AzureVirtualDesktop") + ProvisioningResourceKindAzureVirtualMachine = ProvisioningResourceKind("AzureVirtualMachine") + ProvisioningResourceKindHelmRelease = ProvisioningResourceKind("HelmRelease") ) diff --git a/pkg/apis/provisioning/v1alpha1/entraUserTypes.go b/pkg/apis/provisioning/v1alpha1/entraUserTypes.go index 5fc269f..812a1dc 100644 --- a/pkg/apis/provisioning/v1alpha1/entraUserTypes.go +++ b/pkg/apis/provisioning/v1alpha1/entraUserTypes.go @@ -39,6 +39,7 @@ type EntraUserSpec struct { type EntraUserExportsSpec struct { // The domain or bounded-context in which this user will be used. + // +optional Domain string `json:"domain"` // The initial password for the user diff --git a/pkg/apis/provisioning/v1alpha1/register.go b/pkg/apis/provisioning/v1alpha1/register.go index 20da463..8aee61c 100644 --- a/pkg/apis/provisioning/v1alpha1/register.go +++ b/pkg/apis/provisioning/v1alpha1/register.go @@ -33,6 +33,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &AzureDatabaseList{}, &AzureManagedDatabase{}, &AzureManagedDatabaseList{}, + &AzurePowerShellScript{}, + &AzurePowerShellScriptList{}, &AzureVirtualMachine{}, &AzureVirtualMachineList{}, &AzureVirtualDesktop{}, diff --git a/pkg/apis/provisioning/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/provisioning/v1alpha1/zz_generated.deepcopy.go index c226372..46bce71 100644 --- a/pkg/apis/provisioning/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/provisioning/v1alpha1/zz_generated.deepcopy.go @@ -260,6 +260,105 @@ func (in *AzureManagedInstanceSpec) DeepCopy() *AzureManagedInstanceSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AzurePowerShellScript) DeepCopyInto(out *AzurePowerShellScript) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AzurePowerShellScript. +func (in *AzurePowerShellScript) DeepCopy() *AzurePowerShellScript { + if in == nil { + return nil + } + out := new(AzurePowerShellScript) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AzurePowerShellScript) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AzurePowerShellScriptExportsSpec) DeepCopyInto(out *AzurePowerShellScriptExportsSpec) { + *out = *in + out.ScriptOutputs = in.ScriptOutputs + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AzurePowerShellScriptExportsSpec. +func (in *AzurePowerShellScriptExportsSpec) DeepCopy() *AzurePowerShellScriptExportsSpec { + if in == nil { + return nil + } + out := new(AzurePowerShellScriptExportsSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AzurePowerShellScriptList) DeepCopyInto(out *AzurePowerShellScriptList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]AzurePowerShellScript, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AzurePowerShellScriptList. +func (in *AzurePowerShellScriptList) DeepCopy() *AzurePowerShellScriptList { + if in == nil { + return nil + } + out := new(AzurePowerShellScriptList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AzurePowerShellScriptList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AzurePowerShellScriptSpec) DeepCopyInto(out *AzurePowerShellScriptSpec) { + *out = *in + if in.Exports != nil { + in, out := &in.Exports, &out.Exports + *out = make([]AzurePowerShellScriptExportsSpec, len(*in)) + copy(*out, *in) + } + in.ProvisioningMeta.DeepCopyInto(&out.ProvisioningMeta) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AzurePowerShellScriptSpec. +func (in *AzurePowerShellScriptSpec) DeepCopy() *AzurePowerShellScriptSpec { + if in == nil { + return nil + } + out := new(AzurePowerShellScriptSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AzureStorageContainerSpec) DeepCopyInto(out *AzureStorageContainerSpec) { *out = *in diff --git a/pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscript.go b/pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscript.go new file mode 100644 index 0000000..f8d8b22 --- /dev/null +++ b/pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscript.go @@ -0,0 +1,210 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + v1 "k8s.io/client-go/applyconfigurations/meta/v1" +) + +// AzurePowerShellScriptApplyConfiguration represents an declarative configuration of the AzurePowerShellScript type for use +// with apply. +type AzurePowerShellScriptApplyConfiguration struct { + v1.TypeMetaApplyConfiguration `json:",inline"` + *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + Spec *AzurePowerShellScriptSpecApplyConfiguration `json:"spec,omitempty"` +} + +// AzurePowerShellScript constructs an declarative configuration of the AzurePowerShellScript type for use with +// apply. +func AzurePowerShellScript(name, namespace string) *AzurePowerShellScriptApplyConfiguration { + b := &AzurePowerShellScriptApplyConfiguration{} + b.WithName(name) + b.WithNamespace(namespace) + b.WithKind("AzurePowerShellScript") + b.WithAPIVersion("provisioning.totalsoft.ro/v1alpha1") + return b +} + +// WithKind sets the Kind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Kind field is set to the value of the last call. +func (b *AzurePowerShellScriptApplyConfiguration) WithKind(value string) *AzurePowerShellScriptApplyConfiguration { + b.Kind = &value + return b +} + +// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the APIVersion field is set to the value of the last call. +func (b *AzurePowerShellScriptApplyConfiguration) WithAPIVersion(value string) *AzurePowerShellScriptApplyConfiguration { + b.APIVersion = &value + return b +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *AzurePowerShellScriptApplyConfiguration) WithName(value string) *AzurePowerShellScriptApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Name = &value + return b +} + +// WithGenerateName sets the GenerateName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the GenerateName field is set to the value of the last call. +func (b *AzurePowerShellScriptApplyConfiguration) WithGenerateName(value string) *AzurePowerShellScriptApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.GenerateName = &value + return b +} + +// WithNamespace sets the Namespace field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Namespace field is set to the value of the last call. +func (b *AzurePowerShellScriptApplyConfiguration) WithNamespace(value string) *AzurePowerShellScriptApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Namespace = &value + return b +} + +// WithUID sets the UID field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the UID field is set to the value of the last call. +func (b *AzurePowerShellScriptApplyConfiguration) WithUID(value types.UID) *AzurePowerShellScriptApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.UID = &value + return b +} + +// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ResourceVersion field is set to the value of the last call. +func (b *AzurePowerShellScriptApplyConfiguration) WithResourceVersion(value string) *AzurePowerShellScriptApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ResourceVersion = &value + return b +} + +// WithGeneration sets the Generation field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Generation field is set to the value of the last call. +func (b *AzurePowerShellScriptApplyConfiguration) WithGeneration(value int64) *AzurePowerShellScriptApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Generation = &value + return b +} + +// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CreationTimestamp field is set to the value of the last call. +func (b *AzurePowerShellScriptApplyConfiguration) WithCreationTimestamp(value metav1.Time) *AzurePowerShellScriptApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.CreationTimestamp = &value + return b +} + +// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionTimestamp field is set to the value of the last call. +func (b *AzurePowerShellScriptApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *AzurePowerShellScriptApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionTimestamp = &value + return b +} + +// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. +func (b *AzurePowerShellScriptApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *AzurePowerShellScriptApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionGracePeriodSeconds = &value + return b +} + +// WithLabels puts the entries into the Labels field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Labels field, +// overwriting an existing map entries in Labels field with the same key. +func (b *AzurePowerShellScriptApplyConfiguration) WithLabels(entries map[string]string) *AzurePowerShellScriptApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Labels == nil && len(entries) > 0 { + b.Labels = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Labels[k] = v + } + return b +} + +// WithAnnotations puts the entries into the Annotations field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Annotations field, +// overwriting an existing map entries in Annotations field with the same key. +func (b *AzurePowerShellScriptApplyConfiguration) WithAnnotations(entries map[string]string) *AzurePowerShellScriptApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Annotations == nil && len(entries) > 0 { + b.Annotations = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Annotations[k] = v + } + return b +} + +// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the OwnerReferences field. +func (b *AzurePowerShellScriptApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *AzurePowerShellScriptApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + if values[i] == nil { + panic("nil value passed to WithOwnerReferences") + } + b.OwnerReferences = append(b.OwnerReferences, *values[i]) + } + return b +} + +// WithFinalizers adds the given value to the Finalizers field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Finalizers field. +func (b *AzurePowerShellScriptApplyConfiguration) WithFinalizers(values ...string) *AzurePowerShellScriptApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + b.Finalizers = append(b.Finalizers, values[i]) + } + return b +} + +func (b *AzurePowerShellScriptApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { + if b.ObjectMetaApplyConfiguration == nil { + b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + } +} + +// WithSpec sets the Spec field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Spec field is set to the value of the last call. +func (b *AzurePowerShellScriptApplyConfiguration) WithSpec(value *AzurePowerShellScriptSpecApplyConfiguration) *AzurePowerShellScriptApplyConfiguration { + b.Spec = value + return b +} diff --git a/pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscriptexportsspec.go b/pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscriptexportsspec.go new file mode 100644 index 0000000..9822429 --- /dev/null +++ b/pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscriptexportsspec.go @@ -0,0 +1,48 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +// AzurePowerShellScriptExportsSpecApplyConfiguration represents an declarative configuration of the AzurePowerShellScriptExportsSpec type for use +// with apply. +type AzurePowerShellScriptExportsSpecApplyConfiguration struct { + Domain *string `json:"domain,omitempty"` + ScriptOutputs *ValueExportApplyConfiguration `json:"scriptOutputs,omitempty"` +} + +// AzurePowerShellScriptExportsSpecApplyConfiguration constructs an declarative configuration of the AzurePowerShellScriptExportsSpec type for use with +// apply. +func AzurePowerShellScriptExportsSpec() *AzurePowerShellScriptExportsSpecApplyConfiguration { + return &AzurePowerShellScriptExportsSpecApplyConfiguration{} +} + +// WithDomain sets the Domain field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Domain field is set to the value of the last call. +func (b *AzurePowerShellScriptExportsSpecApplyConfiguration) WithDomain(value string) *AzurePowerShellScriptExportsSpecApplyConfiguration { + b.Domain = &value + return b +} + +// WithScriptOutputs sets the ScriptOutputs field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ScriptOutputs field is set to the value of the last call. +func (b *AzurePowerShellScriptExportsSpecApplyConfiguration) WithScriptOutputs(value *ValueExportApplyConfiguration) *AzurePowerShellScriptExportsSpecApplyConfiguration { + b.ScriptOutputs = value + return b +} diff --git a/pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscriptspec.go b/pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscriptspec.go new file mode 100644 index 0000000..f9b4dab --- /dev/null +++ b/pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscriptspec.go @@ -0,0 +1,136 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" +) + +// AzurePowerShellScriptSpecApplyConfiguration represents an declarative configuration of the AzurePowerShellScriptSpec type for use +// with apply. +type AzurePowerShellScriptSpecApplyConfiguration struct { + ScriptContent *string `json:"scriptContent,omitempty"` + ScriptArguments *string `json:"scriptArguments,omitempty"` + ForceUpdateTag *string `json:"forceUpdateTag,omitempty"` + ManagedIdentity *string `json:"managedIdentity,omitempty"` + Exports []AzurePowerShellScriptExportsSpecApplyConfiguration `json:"exports,omitempty"` + ProvisioningMetaApplyConfiguration `json:",inline"` +} + +// AzurePowerShellScriptSpecApplyConfiguration constructs an declarative configuration of the AzurePowerShellScriptSpec type for use with +// apply. +func AzurePowerShellScriptSpec() *AzurePowerShellScriptSpecApplyConfiguration { + return &AzurePowerShellScriptSpecApplyConfiguration{} +} + +// WithScriptContent sets the ScriptContent field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ScriptContent field is set to the value of the last call. +func (b *AzurePowerShellScriptSpecApplyConfiguration) WithScriptContent(value string) *AzurePowerShellScriptSpecApplyConfiguration { + b.ScriptContent = &value + return b +} + +// WithScriptArguments sets the ScriptArguments field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ScriptArguments field is set to the value of the last call. +func (b *AzurePowerShellScriptSpecApplyConfiguration) WithScriptArguments(value string) *AzurePowerShellScriptSpecApplyConfiguration { + b.ScriptArguments = &value + return b +} + +// WithForceUpdateTag sets the ForceUpdateTag field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ForceUpdateTag field is set to the value of the last call. +func (b *AzurePowerShellScriptSpecApplyConfiguration) WithForceUpdateTag(value string) *AzurePowerShellScriptSpecApplyConfiguration { + b.ForceUpdateTag = &value + return b +} + +// WithManagedIdentity sets the ManagedIdentity field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ManagedIdentity field is set to the value of the last call. +func (b *AzurePowerShellScriptSpecApplyConfiguration) WithManagedIdentity(value string) *AzurePowerShellScriptSpecApplyConfiguration { + b.ManagedIdentity = &value + return b +} + +// WithExports adds the given value to the Exports field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Exports field. +func (b *AzurePowerShellScriptSpecApplyConfiguration) WithExports(values ...*AzurePowerShellScriptExportsSpecApplyConfiguration) *AzurePowerShellScriptSpecApplyConfiguration { + for i := range values { + if values[i] == nil { + panic("nil value passed to WithExports") + } + b.Exports = append(b.Exports, *values[i]) + } + return b +} + +// WithPlatformRef sets the PlatformRef field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the PlatformRef field is set to the value of the last call. +func (b *AzurePowerShellScriptSpecApplyConfiguration) WithPlatformRef(value string) *AzurePowerShellScriptSpecApplyConfiguration { + b.PlatformRef = &value + return b +} + +// WithDomainRef sets the DomainRef field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DomainRef field is set to the value of the last call. +func (b *AzurePowerShellScriptSpecApplyConfiguration) WithDomainRef(value string) *AzurePowerShellScriptSpecApplyConfiguration { + b.DomainRef = &value + return b +} + +// WithTenantOverrides puts the entries into the TenantOverrides field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the TenantOverrides field, +// overwriting an existing map entries in TenantOverrides field with the same key. +func (b *AzurePowerShellScriptSpecApplyConfiguration) WithTenantOverrides(entries map[string]*v1.JSON) *AzurePowerShellScriptSpecApplyConfiguration { + if b.TenantOverrides == nil && len(entries) > 0 { + b.TenantOverrides = make(map[string]*v1.JSON, len(entries)) + } + for k, v := range entries { + b.TenantOverrides[k] = v + } + return b +} + +// WithTarget sets the Target field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Target field is set to the value of the last call. +func (b *AzurePowerShellScriptSpecApplyConfiguration) WithTarget(value *ProvisioningTargetApplyConfiguration) *AzurePowerShellScriptSpecApplyConfiguration { + b.Target = value + return b +} + +// WithDependsOn adds the given value to the DependsOn field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the DependsOn field. +func (b *AzurePowerShellScriptSpecApplyConfiguration) WithDependsOn(values ...*ProvisioningResourceIdendtifierApplyConfiguration) *AzurePowerShellScriptSpecApplyConfiguration { + for i := range values { + if values[i] == nil { + panic("nil value passed to WithDependsOn") + } + b.DependsOn = append(b.DependsOn, *values[i]) + } + return b +} diff --git a/pkg/generated/applyconfiguration/utils.go b/pkg/generated/applyconfiguration/utils.go index 9e5e61c..821cc6b 100644 --- a/pkg/generated/applyconfiguration/utils.go +++ b/pkg/generated/applyconfiguration/utils.go @@ -79,6 +79,12 @@ func ForKind(kind schema.GroupVersionKind) interface{} { return &applyconfigurationprovisioningv1alpha1.AzureManagedDatabaseSpecApplyConfiguration{} case provisioningv1alpha1.SchemeGroupVersion.WithKind("AzureManagedInstanceSpec"): return &applyconfigurationprovisioningv1alpha1.AzureManagedInstanceSpecApplyConfiguration{} + case provisioningv1alpha1.SchemeGroupVersion.WithKind("AzurePowerShellScript"): + return &applyconfigurationprovisioningv1alpha1.AzurePowerShellScriptApplyConfiguration{} + case provisioningv1alpha1.SchemeGroupVersion.WithKind("AzurePowerShellScriptExportsSpec"): + return &applyconfigurationprovisioningv1alpha1.AzurePowerShellScriptExportsSpecApplyConfiguration{} + case provisioningv1alpha1.SchemeGroupVersion.WithKind("AzurePowerShellScriptSpec"): + return &applyconfigurationprovisioningv1alpha1.AzurePowerShellScriptSpecApplyConfiguration{} case provisioningv1alpha1.SchemeGroupVersion.WithKind("AzureStorageContainerSpec"): return &applyconfigurationprovisioningv1alpha1.AzureStorageContainerSpecApplyConfiguration{} case provisioningv1alpha1.SchemeGroupVersion.WithKind("AzureVirtualDesktop"): diff --git a/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/azurepowershellscript.go b/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/azurepowershellscript.go new file mode 100644 index 0000000..ee8fe0f --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/azurepowershellscript.go @@ -0,0 +1,208 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + json "encoding/json" + "fmt" + "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" + v1alpha1 "totalsoft.ro/platform-controllers/pkg/apis/provisioning/v1alpha1" + provisioningv1alpha1 "totalsoft.ro/platform-controllers/pkg/generated/applyconfiguration/provisioning/v1alpha1" + scheme "totalsoft.ro/platform-controllers/pkg/generated/clientset/versioned/scheme" +) + +// AzurePowerShellScriptsGetter has a method to return a AzurePowerShellScriptInterface. +// A group's client should implement this interface. +type AzurePowerShellScriptsGetter interface { + AzurePowerShellScripts(namespace string) AzurePowerShellScriptInterface +} + +// AzurePowerShellScriptInterface has methods to work with AzurePowerShellScript resources. +type AzurePowerShellScriptInterface interface { + Create(ctx context.Context, azurePowerShellScript *v1alpha1.AzurePowerShellScript, opts v1.CreateOptions) (*v1alpha1.AzurePowerShellScript, error) + Update(ctx context.Context, azurePowerShellScript *v1alpha1.AzurePowerShellScript, opts v1.UpdateOptions) (*v1alpha1.AzurePowerShellScript, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.AzurePowerShellScript, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.AzurePowerShellScriptList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.AzurePowerShellScript, err error) + Apply(ctx context.Context, azurePowerShellScript *provisioningv1alpha1.AzurePowerShellScriptApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha1.AzurePowerShellScript, err error) + AzurePowerShellScriptExpansion +} + +// azurePowerShellScripts implements AzurePowerShellScriptInterface +type azurePowerShellScripts struct { + client rest.Interface + ns string +} + +// newAzurePowerShellScripts returns a AzurePowerShellScripts +func newAzurePowerShellScripts(c *ProvisioningV1alpha1Client, namespace string) *azurePowerShellScripts { + return &azurePowerShellScripts{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the azurePowerShellScript, and returns the corresponding azurePowerShellScript object, and an error if there is any. +func (c *azurePowerShellScripts) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.AzurePowerShellScript, err error) { + result = &v1alpha1.AzurePowerShellScript{} + err = c.client.Get(). + Namespace(c.ns). + Resource("azurepowershellscripts"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of AzurePowerShellScripts that match those selectors. +func (c *azurePowerShellScripts) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.AzurePowerShellScriptList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.AzurePowerShellScriptList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("azurepowershellscripts"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested azurePowerShellScripts. +func (c *azurePowerShellScripts) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("azurepowershellscripts"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a azurePowerShellScript and creates it. Returns the server's representation of the azurePowerShellScript, and an error, if there is any. +func (c *azurePowerShellScripts) Create(ctx context.Context, azurePowerShellScript *v1alpha1.AzurePowerShellScript, opts v1.CreateOptions) (result *v1alpha1.AzurePowerShellScript, err error) { + result = &v1alpha1.AzurePowerShellScript{} + err = c.client.Post(). + Namespace(c.ns). + Resource("azurepowershellscripts"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(azurePowerShellScript). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a azurePowerShellScript and updates it. Returns the server's representation of the azurePowerShellScript, and an error, if there is any. +func (c *azurePowerShellScripts) Update(ctx context.Context, azurePowerShellScript *v1alpha1.AzurePowerShellScript, opts v1.UpdateOptions) (result *v1alpha1.AzurePowerShellScript, err error) { + result = &v1alpha1.AzurePowerShellScript{} + err = c.client.Put(). + Namespace(c.ns). + Resource("azurepowershellscripts"). + Name(azurePowerShellScript.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(azurePowerShellScript). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the azurePowerShellScript and deletes it. Returns an error if one occurs. +func (c *azurePowerShellScripts) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("azurepowershellscripts"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *azurePowerShellScripts) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("azurepowershellscripts"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched azurePowerShellScript. +func (c *azurePowerShellScripts) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.AzurePowerShellScript, err error) { + result = &v1alpha1.AzurePowerShellScript{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("azurepowershellscripts"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} + +// Apply takes the given apply declarative configuration, applies it and returns the applied azurePowerShellScript. +func (c *azurePowerShellScripts) Apply(ctx context.Context, azurePowerShellScript *provisioningv1alpha1.AzurePowerShellScriptApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha1.AzurePowerShellScript, err error) { + if azurePowerShellScript == nil { + return nil, fmt.Errorf("azurePowerShellScript provided to Apply must not be nil") + } + patchOpts := opts.ToPatchOptions() + data, err := json.Marshal(azurePowerShellScript) + if err != nil { + return nil, err + } + name := azurePowerShellScript.Name + if name == nil { + return nil, fmt.Errorf("azurePowerShellScript.Name must be provided to Apply") + } + result = &v1alpha1.AzurePowerShellScript{} + err = c.client.Patch(types.ApplyPatchType). + Namespace(c.ns). + Resource("azurepowershellscripts"). + Name(*name). + VersionedParams(&patchOpts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/fake/fake_azurepowershellscript.go b/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/fake/fake_azurepowershellscript.go new file mode 100644 index 0000000..5c9e76b --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/fake/fake_azurepowershellscript.go @@ -0,0 +1,154 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + json "encoding/json" + "fmt" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" + v1alpha1 "totalsoft.ro/platform-controllers/pkg/apis/provisioning/v1alpha1" + provisioningv1alpha1 "totalsoft.ro/platform-controllers/pkg/generated/applyconfiguration/provisioning/v1alpha1" +) + +// FakeAzurePowerShellScripts implements AzurePowerShellScriptInterface +type FakeAzurePowerShellScripts struct { + Fake *FakeProvisioningV1alpha1 + ns string +} + +var azurepowershellscriptsResource = v1alpha1.SchemeGroupVersion.WithResource("azurepowershellscripts") + +var azurepowershellscriptsKind = v1alpha1.SchemeGroupVersion.WithKind("AzurePowerShellScript") + +// Get takes name of the azurePowerShellScript, and returns the corresponding azurePowerShellScript object, and an error if there is any. +func (c *FakeAzurePowerShellScripts) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.AzurePowerShellScript, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(azurepowershellscriptsResource, c.ns, name), &v1alpha1.AzurePowerShellScript{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.AzurePowerShellScript), err +} + +// List takes label and field selectors, and returns the list of AzurePowerShellScripts that match those selectors. +func (c *FakeAzurePowerShellScripts) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.AzurePowerShellScriptList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(azurepowershellscriptsResource, azurepowershellscriptsKind, c.ns, opts), &v1alpha1.AzurePowerShellScriptList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.AzurePowerShellScriptList{ListMeta: obj.(*v1alpha1.AzurePowerShellScriptList).ListMeta} + for _, item := range obj.(*v1alpha1.AzurePowerShellScriptList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested azurePowerShellScripts. +func (c *FakeAzurePowerShellScripts) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(azurepowershellscriptsResource, c.ns, opts)) + +} + +// Create takes the representation of a azurePowerShellScript and creates it. Returns the server's representation of the azurePowerShellScript, and an error, if there is any. +func (c *FakeAzurePowerShellScripts) Create(ctx context.Context, azurePowerShellScript *v1alpha1.AzurePowerShellScript, opts v1.CreateOptions) (result *v1alpha1.AzurePowerShellScript, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(azurepowershellscriptsResource, c.ns, azurePowerShellScript), &v1alpha1.AzurePowerShellScript{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.AzurePowerShellScript), err +} + +// Update takes the representation of a azurePowerShellScript and updates it. Returns the server's representation of the azurePowerShellScript, and an error, if there is any. +func (c *FakeAzurePowerShellScripts) Update(ctx context.Context, azurePowerShellScript *v1alpha1.AzurePowerShellScript, opts v1.UpdateOptions) (result *v1alpha1.AzurePowerShellScript, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(azurepowershellscriptsResource, c.ns, azurePowerShellScript), &v1alpha1.AzurePowerShellScript{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.AzurePowerShellScript), err +} + +// Delete takes name of the azurePowerShellScript and deletes it. Returns an error if one occurs. +func (c *FakeAzurePowerShellScripts) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(azurepowershellscriptsResource, c.ns, name, opts), &v1alpha1.AzurePowerShellScript{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeAzurePowerShellScripts) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(azurepowershellscriptsResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.AzurePowerShellScriptList{}) + return err +} + +// Patch applies the patch and returns the patched azurePowerShellScript. +func (c *FakeAzurePowerShellScripts) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.AzurePowerShellScript, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(azurepowershellscriptsResource, c.ns, name, pt, data, subresources...), &v1alpha1.AzurePowerShellScript{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.AzurePowerShellScript), err +} + +// Apply takes the given apply declarative configuration, applies it and returns the applied azurePowerShellScript. +func (c *FakeAzurePowerShellScripts) Apply(ctx context.Context, azurePowerShellScript *provisioningv1alpha1.AzurePowerShellScriptApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha1.AzurePowerShellScript, err error) { + if azurePowerShellScript == nil { + return nil, fmt.Errorf("azurePowerShellScript provided to Apply must not be nil") + } + data, err := json.Marshal(azurePowerShellScript) + if err != nil { + return nil, err + } + name := azurePowerShellScript.Name + if name == nil { + return nil, fmt.Errorf("azurePowerShellScript.Name must be provided to Apply") + } + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(azurepowershellscriptsResource, c.ns, *name, types.ApplyPatchType, data), &v1alpha1.AzurePowerShellScript{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.AzurePowerShellScript), err +} diff --git a/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/fake/fake_provisioning_client.go b/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/fake/fake_provisioning_client.go index 687584c..6d7a8ea 100644 --- a/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/fake/fake_provisioning_client.go +++ b/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/fake/fake_provisioning_client.go @@ -36,6 +36,10 @@ func (c *FakeProvisioningV1alpha1) AzureManagedDatabases(namespace string) v1alp return &FakeAzureManagedDatabases{c, namespace} } +func (c *FakeProvisioningV1alpha1) AzurePowerShellScripts(namespace string) v1alpha1.AzurePowerShellScriptInterface { + return &FakeAzurePowerShellScripts{c, namespace} +} + func (c *FakeProvisioningV1alpha1) AzureVirtualDesktops(namespace string) v1alpha1.AzureVirtualDesktopInterface { return &FakeAzureVirtualDesktops{c, namespace} } diff --git a/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/generated_expansion.go b/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/generated_expansion.go index 4b6180d..27efc79 100644 --- a/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/generated_expansion.go +++ b/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/generated_expansion.go @@ -22,6 +22,8 @@ type AzureDatabaseExpansion interface{} type AzureManagedDatabaseExpansion interface{} +type AzurePowerShellScriptExpansion interface{} + type AzureVirtualDesktopExpansion interface{} type AzureVirtualMachineExpansion interface{} diff --git a/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/provisioning_client.go b/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/provisioning_client.go index 3694e24..7dab707 100644 --- a/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/provisioning_client.go +++ b/pkg/generated/clientset/versioned/typed/provisioning/v1alpha1/provisioning_client.go @@ -30,6 +30,7 @@ type ProvisioningV1alpha1Interface interface { RESTClient() rest.Interface AzureDatabasesGetter AzureManagedDatabasesGetter + AzurePowerShellScriptsGetter AzureVirtualDesktopsGetter AzureVirtualMachinesGetter EntraUsersGetter @@ -49,6 +50,10 @@ func (c *ProvisioningV1alpha1Client) AzureManagedDatabases(namespace string) Azu return newAzureManagedDatabases(c, namespace) } +func (c *ProvisioningV1alpha1Client) AzurePowerShellScripts(namespace string) AzurePowerShellScriptInterface { + return newAzurePowerShellScripts(c, namespace) +} + func (c *ProvisioningV1alpha1Client) AzureVirtualDesktops(namespace string) AzureVirtualDesktopInterface { return newAzureVirtualDesktops(c, namespace) } diff --git a/pkg/generated/informers/externalversions/generic.go b/pkg/generated/informers/externalversions/generic.go index 322a753..11b9e8a 100644 --- a/pkg/generated/informers/externalversions/generic.go +++ b/pkg/generated/informers/externalversions/generic.go @@ -73,6 +73,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Provisioning().V1alpha1().AzureDatabases().Informer()}, nil case provisioningv1alpha1.SchemeGroupVersion.WithResource("azuremanageddatabases"): return &genericInformer{resource: resource.GroupResource(), informer: f.Provisioning().V1alpha1().AzureManagedDatabases().Informer()}, nil + case provisioningv1alpha1.SchemeGroupVersion.WithResource("azurepowershellscripts"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Provisioning().V1alpha1().AzurePowerShellScripts().Informer()}, nil case provisioningv1alpha1.SchemeGroupVersion.WithResource("azurevirtualdesktops"): return &genericInformer{resource: resource.GroupResource(), informer: f.Provisioning().V1alpha1().AzureVirtualDesktops().Informer()}, nil case provisioningv1alpha1.SchemeGroupVersion.WithResource("azurevirtualmachines"): diff --git a/pkg/generated/informers/externalversions/provisioning/v1alpha1/azurepowershellscript.go b/pkg/generated/informers/externalversions/provisioning/v1alpha1/azurepowershellscript.go new file mode 100644 index 0000000..96b3816 --- /dev/null +++ b/pkg/generated/informers/externalversions/provisioning/v1alpha1/azurepowershellscript.go @@ -0,0 +1,90 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + time "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + provisioningv1alpha1 "totalsoft.ro/platform-controllers/pkg/apis/provisioning/v1alpha1" + versioned "totalsoft.ro/platform-controllers/pkg/generated/clientset/versioned" + internalinterfaces "totalsoft.ro/platform-controllers/pkg/generated/informers/externalversions/internalinterfaces" + v1alpha1 "totalsoft.ro/platform-controllers/pkg/generated/listers/provisioning/v1alpha1" +) + +// AzurePowerShellScriptInformer provides access to a shared informer and lister for +// AzurePowerShellScripts. +type AzurePowerShellScriptInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.AzurePowerShellScriptLister +} + +type azurePowerShellScriptInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewAzurePowerShellScriptInformer constructs a new informer for AzurePowerShellScript type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewAzurePowerShellScriptInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredAzurePowerShellScriptInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredAzurePowerShellScriptInformer constructs a new informer for AzurePowerShellScript type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredAzurePowerShellScriptInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ProvisioningV1alpha1().AzurePowerShellScripts(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ProvisioningV1alpha1().AzurePowerShellScripts(namespace).Watch(context.TODO(), options) + }, + }, + &provisioningv1alpha1.AzurePowerShellScript{}, + resyncPeriod, + indexers, + ) +} + +func (f *azurePowerShellScriptInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredAzurePowerShellScriptInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *azurePowerShellScriptInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&provisioningv1alpha1.AzurePowerShellScript{}, f.defaultInformer) +} + +func (f *azurePowerShellScriptInformer) Lister() v1alpha1.AzurePowerShellScriptLister { + return v1alpha1.NewAzurePowerShellScriptLister(f.Informer().GetIndexer()) +} diff --git a/pkg/generated/informers/externalversions/provisioning/v1alpha1/interface.go b/pkg/generated/informers/externalversions/provisioning/v1alpha1/interface.go index 1b038af..3bacd39 100644 --- a/pkg/generated/informers/externalversions/provisioning/v1alpha1/interface.go +++ b/pkg/generated/informers/externalversions/provisioning/v1alpha1/interface.go @@ -28,6 +28,8 @@ type Interface interface { AzureDatabases() AzureDatabaseInformer // AzureManagedDatabases returns a AzureManagedDatabaseInformer. AzureManagedDatabases() AzureManagedDatabaseInformer + // AzurePowerShellScripts returns a AzurePowerShellScriptInformer. + AzurePowerShellScripts() AzurePowerShellScriptInformer // AzureVirtualDesktops returns a AzureVirtualDesktopInformer. AzureVirtualDesktops() AzureVirtualDesktopInformer // AzureVirtualMachines returns a AzureVirtualMachineInformer. @@ -59,6 +61,11 @@ func (v *version) AzureManagedDatabases() AzureManagedDatabaseInformer { return &azureManagedDatabaseInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } +// AzurePowerShellScripts returns a AzurePowerShellScriptInformer. +func (v *version) AzurePowerShellScripts() AzurePowerShellScriptInformer { + return &azurePowerShellScriptInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + // AzureVirtualDesktops returns a AzureVirtualDesktopInformer. func (v *version) AzureVirtualDesktops() AzureVirtualDesktopInformer { return &azureVirtualDesktopInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} diff --git a/pkg/generated/listers/provisioning/v1alpha1/azurepowershellscript.go b/pkg/generated/listers/provisioning/v1alpha1/azurepowershellscript.go new file mode 100644 index 0000000..0fce4a7 --- /dev/null +++ b/pkg/generated/listers/provisioning/v1alpha1/azurepowershellscript.go @@ -0,0 +1,99 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + v1alpha1 "totalsoft.ro/platform-controllers/pkg/apis/provisioning/v1alpha1" +) + +// AzurePowerShellScriptLister helps list AzurePowerShellScripts. +// All objects returned here must be treated as read-only. +type AzurePowerShellScriptLister interface { + // List lists all AzurePowerShellScripts in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.AzurePowerShellScript, err error) + // AzurePowerShellScripts returns an object that can list and get AzurePowerShellScripts. + AzurePowerShellScripts(namespace string) AzurePowerShellScriptNamespaceLister + AzurePowerShellScriptListerExpansion +} + +// azurePowerShellScriptLister implements the AzurePowerShellScriptLister interface. +type azurePowerShellScriptLister struct { + indexer cache.Indexer +} + +// NewAzurePowerShellScriptLister returns a new AzurePowerShellScriptLister. +func NewAzurePowerShellScriptLister(indexer cache.Indexer) AzurePowerShellScriptLister { + return &azurePowerShellScriptLister{indexer: indexer} +} + +// List lists all AzurePowerShellScripts in the indexer. +func (s *azurePowerShellScriptLister) List(selector labels.Selector) (ret []*v1alpha1.AzurePowerShellScript, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.AzurePowerShellScript)) + }) + return ret, err +} + +// AzurePowerShellScripts returns an object that can list and get AzurePowerShellScripts. +func (s *azurePowerShellScriptLister) AzurePowerShellScripts(namespace string) AzurePowerShellScriptNamespaceLister { + return azurePowerShellScriptNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// AzurePowerShellScriptNamespaceLister helps list and get AzurePowerShellScripts. +// All objects returned here must be treated as read-only. +type AzurePowerShellScriptNamespaceLister interface { + // List lists all AzurePowerShellScripts in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.AzurePowerShellScript, err error) + // Get retrieves the AzurePowerShellScript from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha1.AzurePowerShellScript, error) + AzurePowerShellScriptNamespaceListerExpansion +} + +// azurePowerShellScriptNamespaceLister implements the AzurePowerShellScriptNamespaceLister +// interface. +type azurePowerShellScriptNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all AzurePowerShellScripts in the indexer for a given namespace. +func (s azurePowerShellScriptNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.AzurePowerShellScript, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.AzurePowerShellScript)) + }) + return ret, err +} + +// Get retrieves the AzurePowerShellScript from the indexer for a given namespace and name. +func (s azurePowerShellScriptNamespaceLister) Get(name string) (*v1alpha1.AzurePowerShellScript, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("azurepowershellscript"), name) + } + return obj.(*v1alpha1.AzurePowerShellScript), nil +} diff --git a/pkg/generated/listers/provisioning/v1alpha1/expansion_generated.go b/pkg/generated/listers/provisioning/v1alpha1/expansion_generated.go index ced29de..670e35a 100644 --- a/pkg/generated/listers/provisioning/v1alpha1/expansion_generated.go +++ b/pkg/generated/listers/provisioning/v1alpha1/expansion_generated.go @@ -34,6 +34,14 @@ type AzureManagedDatabaseListerExpansion interface{} // AzureManagedDatabaseNamespaceLister. type AzureManagedDatabaseNamespaceListerExpansion interface{} +// AzurePowerShellScriptListerExpansion allows custom methods to be added to +// AzurePowerShellScriptLister. +type AzurePowerShellScriptListerExpansion interface{} + +// AzurePowerShellScriptNamespaceListerExpansion allows custom methods to be added to +// AzurePowerShellScriptNamespaceLister. +type AzurePowerShellScriptNamespaceListerExpansion interface{} + // AzureVirtualDesktopListerExpansion allows custom methods to be added to // AzureVirtualDesktopLister. type AzureVirtualDesktopListerExpansion interface{} From 7b6603ed5fa9a31495fc38dd208d8084a17bc693 Mon Sep 17 00:00:00 2001 From: fraliv13 <5892139+fraliv13@users.noreply.github.com> Date: Mon, 12 Feb 2024 14:36:07 +0200 Subject: [PATCH 2/5] Tests and readme --- README.md | 48 +++++++++++++++++++ .../pulumi/eazure_powershell_script_test.go | 38 +++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 internal/controllers/provisioning/provisioners/pulumi/eazure_powershell_script_test.go diff --git a/README.md b/README.md index 9628362..530b919 100644 --- a/README.md +++ b/README.md @@ -326,6 +326,54 @@ spec: workspaceFriendlyName: Charisma ``` +### AzurePowershellScript +`AzurePowershellScript` is a Custom Resource Definition (CRD) that represents an Azure PowerShell deployment script. + +Definition can be found [here](./helm/crds/provisioning.totalsoft.ro_azurepowershellscripts.yaml) + +#### Spec +The `AzurePowershellScript` spec has the following fields: + +- `scriptContent`: The content of the PowerShell script to be executed. +- `scriptArguments`: The arguments to be passed to the PowerShell script. These should match the parameters defined in the scriptContent. +- `managedIdentity`: The Azure Resource Manager (ARM) identifier of the managed identity used to run the script. +- `domainRef`: The reference to the domain that the user belongs to. +- `platformRef`: The reference to the platform that the user belongs to. +- `forceUpdateTag`: Update this value to trigger the script even if the content or args are unchanged + +Example: +```yaml +apiVersion: provisioning.totalsoft.ro/v1alpha1 +kind: AzurePowerShellScript +metadata: + name: createresourcegroup + namespace: provisioning-test +spec: + domainRef: domain2 + exports: + - scriptOutputs: + toConfigMap: + keyTemplate: MultiTenancy__Tenants__{{ .Tenant.Code }}__ScriptOutputs + managedIdentity: >- + /subscriptions/15b38e46-ef41-4f5b-bdba-7d9354568c2d/resourceGroups/global/providers/Microsoft.ManagedIdentity/userAssignedIdentities/scriptidentity + platformRef: provisioning.test + scriptContent: |- + param([string] $name) + + $output = "RG name: {0}" -f $name + Write-Output $output + + $DeploymentScriptOutputs = @{} + $DeploymentScriptOutputs['text'] = $output + + New-AzResourceGroup $name "West Europe" + scriptArguments: "-name testrg-{{ .Platform }}-{{ .Tenant.Code }}" + target: + category: Tenant +``` + + + ### EntraUser `EntraUser` is a Custom Resource Definition (CRD) that represents a user for Entra Id. diff --git a/internal/controllers/provisioning/provisioners/pulumi/eazure_powershell_script_test.go b/internal/controllers/provisioning/provisioners/pulumi/eazure_powershell_script_test.go new file mode 100644 index 0000000..269a17e --- /dev/null +++ b/internal/controllers/provisioning/provisioners/pulumi/eazure_powershell_script_test.go @@ -0,0 +1,38 @@ +package pulumi + +import ( + "testing" + + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" + "github.com/stretchr/testify/assert" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + provisioningv1 "totalsoft.ro/platform-controllers/pkg/apis/provisioning/v1alpha1" +) + +func TestDeployAzurePowerShellScript(t *testing.T) { + t.Run("maximal entra user spec", func(t *testing.T) { + platform := "dev" + tenant := newTenant("tenant1", platform) + script := &provisioningv1.AzurePowerShellScript{ + ObjectMeta: metav1.ObjectMeta{ + Name: "my-pwsh-script", + }, + Spec: provisioningv1.AzurePowerShellScriptSpec{ + ScriptContent: "Write-Host 'Hello, World!'", + ManagedIdentity: "my-managed-identity", + ProvisioningMeta: provisioningv1.ProvisioningMeta{ + DomainRef: "example-domain", + }, + }, + } + + err := pulumi.RunErr(func(ctx *pulumi.Context) error { + script, err := deployAzurePowerShellScript(tenant, pulumi.String("rg").ToStringOutput(), script, []pulumi.Resource{}, ctx) + assert.NoError(t, err) + assert.NotNil(t, script) + return nil + + }, pulumi.WithMocks("project", "stack", mocks(0))) + assert.NoError(t, err) + }) +} From f6a17eb6fd2a893fcbf142cdec80c968e631be3e Mon Sep 17 00:00:00 2001 From: fraliv13 <5892139+fraliv13@users.noreply.github.com> Date: Mon, 12 Feb 2024 14:47:18 +0200 Subject: [PATCH 3/5] typo --- ..._powershell_script_test.go => azure_powershell_script_test.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename internal/controllers/provisioning/provisioners/pulumi/{eazure_powershell_script_test.go => azure_powershell_script_test.go} (100%) diff --git a/internal/controllers/provisioning/provisioners/pulumi/eazure_powershell_script_test.go b/internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script_test.go similarity index 100% rename from internal/controllers/provisioning/provisioners/pulumi/eazure_powershell_script_test.go rename to internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script_test.go From 3ef7d74695b673cc4ee78e2063c428bcdb6a06e1 Mon Sep 17 00:00:00 2001 From: fraliv13 <5892139+fraliv13@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:29:37 +0200 Subject: [PATCH 4/5] ManagedIdentity configuration static --- .vscode/launch.json | 6 ++++-- README.md | 5 +---- go.mod | 1 + go.sum | 2 ++ ...oning.totalsoft.ro_azurepowershellscripts.yaml | 5 ----- helm/templates/provisioner-deployment.yaml | 10 ++++++++++ .../pulumi/azure_powershell_script.go | 15 ++++++++++++++- ...t_test.go => eazure_powershell_script_test.go} | 3 +-- .../v1alpha1/azurePowershelScriptTypes.go | 3 --- .../v1alpha1/azurepowershellscriptspec.go | 9 --------- 10 files changed, 33 insertions(+), 26 deletions(-) rename internal/controllers/provisioning/provisioners/pulumi/{azure_powershell_script_test.go => eazure_powershell_script_test.go} (91%) diff --git a/.vscode/launch.json b/.vscode/launch.json index bd5f66b..851c6e7 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -27,8 +27,10 @@ ], "env": { "AZURE_LOCATION": "West Europe", - "VAULT_ADDR": "http://localhost:62293/", - //"VAULT_TOKEN": "PLEASE_ADD_VAULT_TOKEN"", + "VAULT_ADDR": "http://localhost:54969/", + "VAULT_TOKEN": "", + "AZURE_MANAGED_IDENTITY_RG": "global", + "AZURE_MANAGED_IDENTITY_NAME": "scriptidentity", //"RUSI_ENABLED": "true" //"PULUMI_SKIP_REFRESH": "true", }, diff --git a/README.md b/README.md index 530b919..693e110 100644 --- a/README.md +++ b/README.md @@ -336,7 +336,6 @@ The `AzurePowershellScript` spec has the following fields: - `scriptContent`: The content of the PowerShell script to be executed. - `scriptArguments`: The arguments to be passed to the PowerShell script. These should match the parameters defined in the scriptContent. -- `managedIdentity`: The Azure Resource Manager (ARM) identifier of the managed identity used to run the script. - `domainRef`: The reference to the domain that the user belongs to. - `platformRef`: The reference to the platform that the user belongs to. - `forceUpdateTag`: Update this value to trigger the script even if the content or args are unchanged @@ -353,9 +352,7 @@ spec: exports: - scriptOutputs: toConfigMap: - keyTemplate: MultiTenancy__Tenants__{{ .Tenant.Code }}__ScriptOutputs - managedIdentity: >- - /subscriptions/15b38e46-ef41-4f5b-bdba-7d9354568c2d/resourceGroups/global/providers/Microsoft.ManagedIdentity/userAssignedIdentities/scriptidentity + keyTemplate: MultiTenancy__Tenants__{{ .Tenant.Code }}__ScriptOutputs platformRef: provisioning.test scriptContent: |- param([string] $name) diff --git a/go.mod b/go.mod index 442e045..369fd0c 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/pulumi/pulumi-azure-native-sdk/authorization/v2 v2.4.0 github.com/pulumi/pulumi-azure-native-sdk/compute/v2 v2.4.0 github.com/pulumi/pulumi-azure-native-sdk/desktopvirtualization/v2 v2.4.0 + github.com/pulumi/pulumi-azure-native-sdk/managedidentity/v2 v2.4.0 github.com/pulumi/pulumi-azure-native-sdk/network/v2 v2.4.0 github.com/pulumi/pulumi-azure-native-sdk/resources/v2 v2.4.0 github.com/pulumi/pulumi-azure-native-sdk/sql/v2 v2.4.0 diff --git a/go.sum b/go.sum index 5f697c2..a425d14 100644 --- a/go.sum +++ b/go.sum @@ -244,6 +244,8 @@ github.com/pulumi/pulumi-azure-native-sdk/compute/v2 v2.4.0 h1:h6SVlNPqa8Spxya7G github.com/pulumi/pulumi-azure-native-sdk/compute/v2 v2.4.0/go.mod h1:eD5kkSSQU2kJbW7telpS9gaM6hiRH4Q8u4lcOpx8jrc= github.com/pulumi/pulumi-azure-native-sdk/desktopvirtualization/v2 v2.4.0 h1:pz8cmyWEFE4qfGGDBAGMQ35pWckM2OOSxgY1cK9e4JI= github.com/pulumi/pulumi-azure-native-sdk/desktopvirtualization/v2 v2.4.0/go.mod h1:s7GSMVekCyCrWTEA3aOdVDtOVkIqTW0yrMnWlWG+4V8= +github.com/pulumi/pulumi-azure-native-sdk/managedidentity/v2 v2.4.0 h1:94XmWZiARdqexr5Sm+PW+tnxQ0VT5lRIXxrWO/WcHJQ= +github.com/pulumi/pulumi-azure-native-sdk/managedidentity/v2 v2.4.0/go.mod h1:JT+ptHaDSxTWwZYmnwKCewX8imIsBE5c49gryfOI5nY= github.com/pulumi/pulumi-azure-native-sdk/network/v2 v2.4.0 h1:KrMG6wvPQuBEqbECNotGBWEuhEEoArN9ndcdkKIzWIY= github.com/pulumi/pulumi-azure-native-sdk/network/v2 v2.4.0/go.mod h1:vszGWHBWdeTWzIIHR7ka04NGQh0GHyVK/yhAbtIEnA4= github.com/pulumi/pulumi-azure-native-sdk/resources/v2 v2.4.0 h1:xqKfg8BZSQxZFrTtj06Qjjro7yyOiep58+N6hszLSJE= diff --git a/helm/crds/provisioning.totalsoft.ro_azurepowershellscripts.yaml b/helm/crds/provisioning.totalsoft.ro_azurepowershellscripts.yaml index b6d2d0d..d809c55 100644 --- a/helm/crds/provisioning.totalsoft.ro_azurepowershellscripts.yaml +++ b/helm/crds/provisioning.totalsoft.ro_azurepowershellscripts.yaml @@ -96,10 +96,6 @@ spec: description: Change value to force the script to execute even if it has not changed. type: string - managedIdentity: - description: Represents the managed identity used to run the Azure - PowerShell. - type: string platformRef: description: Target platform (custom resource name). type: string @@ -158,7 +154,6 @@ spec: type: object required: - domainRef - - managedIdentity - platformRef - scriptContent - target diff --git a/helm/templates/provisioner-deployment.yaml b/helm/templates/provisioner-deployment.yaml index 04f68dd..d8844f4 100644 --- a/helm/templates/provisioner-deployment.yaml +++ b/helm/templates/provisioner-deployment.yaml @@ -56,6 +56,16 @@ spec: configMapKeyRef: name: azure-config key: tenantId + - name: AZURE_MANAGED_IDENTITY_RG + valueFrom: + configMapKeyRef: + name: azure-config + key: managedIdentityRG + - name: AZURE_MANAGED_IDENTITY_NAME + valueFrom: + configMapKeyRef: + name: azure-config + key: managedIdentityName - name: ARM_CLIENT_ID valueFrom: configMapKeyRef: diff --git a/internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script.go b/internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script.go index 79acaee..6427e61 100644 --- a/internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script.go +++ b/internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script.go @@ -2,7 +2,9 @@ package pulumi import ( "encoding/json" + "os" + "github.com/pulumi/pulumi-azure-native-sdk/managedidentity/v2" "github.com/pulumi/pulumi-azure-native-sdk/resources/v2" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" "totalsoft.ro/platform-controllers/internal/controllers/provisioning" @@ -26,6 +28,17 @@ func deployAzurePowerShellScript(target provisioning.ProvisioningTarget, return nil, err } + os.Getenv("AZURE_MANAGED_IDENTITY_RG") + + managedIdentity, err := managedidentity.LookupUserAssignedIdentity(ctx, &managedidentity.LookupUserAssignedIdentityArgs{ + ResourceGroupName: os.Getenv("AZURE_MANAGED_IDENTITY_RG"), + ResourceName: os.Getenv("AZURE_MANAGED_IDENTITY_NAME"), + }) + + if err != nil { + return nil, err + } + script, err := resources.NewAzurePowerShellScript(ctx, azurePowerShellScript.Name, &resources.AzurePowerShellScriptArgs{ Kind: pulumi.String("AzurePowerShell"), ForceUpdateTag: pulumi.String(azurePowerShellScript.Spec.ForceUpdateTag), // Change to force redeploying the script if desired @@ -37,7 +50,7 @@ func deployAzurePowerShellScript(target provisioning.ProvisioningTarget, Identity: &resources.ManagedServiceIdentityArgs{ Type: pulumi.String(resources.ManagedServiceIdentityTypeUserAssigned), UserAssignedIdentities: pulumi.StringArray{ - pulumi.String(azurePowerShellScript.Spec.ManagedIdentity), + pulumi.String(managedIdentity.Id), }, }, AzPowerShellVersion: pulumi.String("11.0"), // Specify the desired version of Az PowerShell module diff --git a/internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script_test.go b/internal/controllers/provisioning/provisioners/pulumi/eazure_powershell_script_test.go similarity index 91% rename from internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script_test.go rename to internal/controllers/provisioning/provisioners/pulumi/eazure_powershell_script_test.go index 269a17e..80f26c8 100644 --- a/internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script_test.go +++ b/internal/controllers/provisioning/provisioners/pulumi/eazure_powershell_script_test.go @@ -18,8 +18,7 @@ func TestDeployAzurePowerShellScript(t *testing.T) { Name: "my-pwsh-script", }, Spec: provisioningv1.AzurePowerShellScriptSpec{ - ScriptContent: "Write-Host 'Hello, World!'", - ManagedIdentity: "my-managed-identity", + ScriptContent: "Write-Host 'Hello, World!'", ProvisioningMeta: provisioningv1.ProvisioningMeta{ DomainRef: "example-domain", }, diff --git a/pkg/apis/provisioning/v1alpha1/azurePowershelScriptTypes.go b/pkg/apis/provisioning/v1alpha1/azurePowershelScriptTypes.go index ac7ee5f..5aef5b5 100644 --- a/pkg/apis/provisioning/v1alpha1/azurePowershelScriptTypes.go +++ b/pkg/apis/provisioning/v1alpha1/azurePowershelScriptTypes.go @@ -31,9 +31,6 @@ type AzurePowerShellScriptSpec struct { // Change value to force the script to execute even if it has not changed. ForceUpdateTag string `json:"forceUpdateTag,omitempty"` - // Represents the managed identity used to run the Azure PowerShell. - ManagedIdentity string `json:"managedIdentity"` - // Export provisioning values spec. // +optional Exports []AzurePowerShellScriptExportsSpec `json:"exports,omitempty"` diff --git a/pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscriptspec.go b/pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscriptspec.go index f9b4dab..05d668b 100644 --- a/pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscriptspec.go +++ b/pkg/generated/applyconfiguration/provisioning/v1alpha1/azurepowershellscriptspec.go @@ -28,7 +28,6 @@ type AzurePowerShellScriptSpecApplyConfiguration struct { ScriptContent *string `json:"scriptContent,omitempty"` ScriptArguments *string `json:"scriptArguments,omitempty"` ForceUpdateTag *string `json:"forceUpdateTag,omitempty"` - ManagedIdentity *string `json:"managedIdentity,omitempty"` Exports []AzurePowerShellScriptExportsSpecApplyConfiguration `json:"exports,omitempty"` ProvisioningMetaApplyConfiguration `json:",inline"` } @@ -63,14 +62,6 @@ func (b *AzurePowerShellScriptSpecApplyConfiguration) WithForceUpdateTag(value s return b } -// WithManagedIdentity sets the ManagedIdentity field in the declarative configuration to the given value -// and returns the receiver, so that objects can be built by chaining "With" function invocations. -// If called multiple times, the ManagedIdentity field is set to the value of the last call. -func (b *AzurePowerShellScriptSpecApplyConfiguration) WithManagedIdentity(value string) *AzurePowerShellScriptSpecApplyConfiguration { - b.ManagedIdentity = &value - return b -} - // WithExports adds the given value to the Exports field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the Exports field. From 75096b312c9c605e9ff363b2676ee6273d15c41f Mon Sep 17 00:00:00 2001 From: fraliv13 <5892139+fraliv13@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:39:43 +0200 Subject: [PATCH 5/5] fixes --- .vscode/launch.json | 2 +- .../provisioning/provisioners/pulumi/azure_powershell_script.go | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 851c6e7..071a5db 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -28,7 +28,7 @@ "env": { "AZURE_LOCATION": "West Europe", "VAULT_ADDR": "http://localhost:54969/", - "VAULT_TOKEN": "", + //"VAULT_TOKEN": "PLEASE_ADD_VAULT_TOKEN"", "AZURE_MANAGED_IDENTITY_RG": "global", "AZURE_MANAGED_IDENTITY_NAME": "scriptidentity", //"RUSI_ENABLED": "true" diff --git a/internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script.go b/internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script.go index 6427e61..11342f1 100644 --- a/internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script.go +++ b/internal/controllers/provisioning/provisioners/pulumi/azure_powershell_script.go @@ -28,8 +28,6 @@ func deployAzurePowerShellScript(target provisioning.ProvisioningTarget, return nil, err } - os.Getenv("AZURE_MANAGED_IDENTITY_RG") - managedIdentity, err := managedidentity.LookupUserAssignedIdentity(ctx, &managedidentity.LookupUserAssignedIdentityArgs{ ResourceGroupName: os.Getenv("AZURE_MANAGED_IDENTITY_RG"), ResourceName: os.Getenv("AZURE_MANAGED_IDENTITY_NAME"),