sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/services/vmextensions/spec.go (about) 1 /* 2 Copyright 2022 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package vmextensions 18 19 import ( 20 "context" 21 22 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" 23 "github.com/pkg/errors" 24 "k8s.io/utils/ptr" 25 "sigs.k8s.io/cluster-api-provider-azure/azure" 26 ) 27 28 // VMExtensionSpec defines the specification for a VM or VMScaleSet extension. 29 type VMExtensionSpec struct { 30 azure.ExtensionSpec 31 ResourceGroup string 32 Location string 33 } 34 35 // ResourceName returns the name of the VM extension. 36 func (s *VMExtensionSpec) ResourceName() string { 37 return s.Name 38 } 39 40 // ResourceGroupName returns the name of the resource group. 41 func (s *VMExtensionSpec) ResourceGroupName() string { 42 return s.ResourceGroup 43 } 44 45 // OwnerResourceName returns the name of the VM that owns this VM extension. 46 func (s *VMExtensionSpec) OwnerResourceName() string { 47 return s.VMName 48 } 49 50 // Parameters returns the parameters for the VM extension. 51 func (s *VMExtensionSpec) Parameters(ctx context.Context, existing interface{}) (interface{}, error) { 52 if existing != nil { 53 _, ok := existing.(armcompute.VirtualMachineExtension) 54 if !ok { 55 return nil, errors.Errorf("%T is not an armcompute.VirtualMachineExtension", existing) 56 } 57 58 // VM extension already exists, nothing to update. 59 return nil, nil 60 } 61 62 return armcompute.VirtualMachineExtension{ 63 Properties: &armcompute.VirtualMachineExtensionProperties{ 64 Publisher: ptr.To(s.Publisher), 65 Type: ptr.To(s.Name), 66 TypeHandlerVersion: ptr.To(s.Version), 67 Settings: s.Settings, 68 ProtectedSettings: s.ProtectedSettings, 69 }, 70 Location: ptr.To(s.Location), 71 }, nil 72 }