@@ -48,6 +48,7 @@ import (
4848 "github.com/kubermatic/machine-controller/pkg/providerconfig"
4949 providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
5050
51+ cloudproviderutil "github.com/kubermatic/machine-controller/pkg/cloudprovider/util"
5152 "k8s.io/apimachinery/pkg/api/meta"
5253 v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5354 "k8s.io/apimachinery/pkg/runtime"
@@ -107,7 +108,7 @@ func (p *provider) Create(ctx context.Context, log *zap.SugaredLogger, machine *
107108 Machine : machine ,
108109 })
109110
110- _ , client , err := getClient (config .Token )
111+ _ , client , err := getClient (config .Token , & machine . Name )
111112 if err != nil {
112113 return nil , err
113114 }
@@ -161,6 +162,10 @@ func provisionVM(ctx context.Context, log *zap.SugaredLogger, client anxclient.C
161162
162163 vm .DiskType = config .Disks [0 ].PerformanceType
163164
165+ if config .CPUPerformanceType != "" {
166+ vm .CPUPerformanceType = config .CPUPerformanceType
167+ }
168+
164169 for _ , disk := range config .Disks [1 :] {
165170 vm .AdditionalDisks = append (vm .AdditionalDisks , anxvm.AdditionalDisk {
166171 SizeGBs : disk .Size ,
@@ -334,7 +339,7 @@ func (p *provider) resolveConfig(ctx context.Context, log *zap.SugaredLogger, co
334339
335340 // when "templateID" is not set, we expect "template" to be
336341 if ret .TemplateID == "" {
337- a , _ , err := getClient (ret .Token )
342+ a , _ , err := getClient (ret .Token , nil )
338343 if err != nil {
339344 return nil , fmt .Errorf ("failed initializing API clients: %w" , err )
340345 }
@@ -467,7 +472,7 @@ func (p *provider) Get(ctx context.Context, log *zap.SugaredLogger, machine *clu
467472 return nil , newError (common .InvalidConfigurationMachineError , "failed to retrieve config: %v" , err )
468473 }
469474
470- _ , cli , err := getClient (config .Token )
475+ _ , cli , err := getClient (config .Token , & machine . Name )
471476 if err != nil {
472477 return nil , newError (common .InvalidConfigurationMachineError , "failed to create Anexia client: %v" , err )
473478 }
@@ -553,7 +558,7 @@ func (p *provider) Cleanup(ctx context.Context, log *zap.SugaredLogger, machine
553558 return false , newError (common .InvalidConfigurationMachineError , "failed to parse MachineSpec: %v" , err )
554559 }
555560
556- _ , cli , err := getClient (config .Token )
561+ _ , cli , err := getClient (config .Token , & machine . Name )
557562 if err != nil {
558563 return false , newError (common .InvalidConfigurationMachineError , "failed to create Anexia client: %v" , err )
559564 }
@@ -568,10 +573,20 @@ func (p *provider) Cleanup(ctx context.Context, log *zap.SugaredLogger, machine
568573 response , err := vsphereAPI .Provisioning ().VM ().Deprovision (deleteCtx , status .InstanceID , false )
569574 if err != nil {
570575 var respErr * anxclient.ResponseError
576+
571577 // Only error if the error was not "not found"
572578 if ! (errors .As (err , & respErr ) && respErr .ErrorData .Code == http .StatusNotFound ) {
573579 return false , newError (common .DeleteMachineError , "failed to delete machine: %v" , err )
574580 }
581+
582+ // good thinking checking for a "not found" error, but go-anxcloud does only
583+ // return >= 500 && < 600 errors (:
584+ // since that's the legacy client in go-anxcloud and the new one is not yet available,
585+ // this will not be fixed there but we have a nice workaround here:
586+
587+ if response .Identifier == "" {
588+ return true , nil
589+ }
575590 }
576591 status .DeprovisioningID = response .Identifier
577592 }
@@ -609,16 +624,29 @@ func (p *provider) SetMetricsForMachines(_ clusterv1alpha1.MachineList) error {
609624 return nil
610625}
611626
612- func getClient (token string ) (api.API , anxclient.Client , error ) {
613- tokenOpt := anxclient .TokenFromString (token )
614- client := anxclient .HTTPClient (& http.Client {Timeout : 120 * time .Second })
627+ func getClient (token string , machineName * string ) (api.API , anxclient.Client , error ) {
628+ logPrefix := "[Anexia API]"
629+
630+ if machineName != nil {
631+ logPrefix = fmt .Sprintf ("[Anexia API for Machine %q]" , * machineName )
632+ }
633+
634+ httpClient := cloudproviderutil.HTTPClientConfig {
635+ Timeout : 120 * time .Second ,
636+ LogPrefix : logPrefix ,
637+ }.New ()
638+
639+ legacyClientOptions := []anxclient.Option {
640+ anxclient .TokenFromString (token ),
641+ anxclient .HTTPClient (& httpClient ),
642+ }
615643
616- a , err := api .NewAPI (api .WithClientOptions (client , tokenOpt ))
644+ a , err := api .NewAPI (api .WithClientOptions (legacyClientOptions ... ))
617645 if err != nil {
618646 return nil , nil , fmt .Errorf ("error creating generic API client: %w" , err )
619647 }
620648
621- legacyClient , err := anxclient .New (tokenOpt , client )
649+ legacyClient , err := anxclient .New (legacyClientOptions ... )
622650 if err != nil {
623651 return nil , nil , fmt .Errorf ("error creating legacy client: %w" , err )
624652 }
0 commit comments