Skip to content

Commit 4d9d4b0

Browse files
committed
remove custom affinitygroup conversion
2 parents 4306e61 + 69dd5bd commit 4d9d4b0

File tree

3 files changed

+21
-86
lines changed

3 files changed

+21
-86
lines changed

api/v1beta1/cloudstackaffinitygroup_conversion.go

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20-
"context"
21-
"fmt"
22-
"github.com/apache/cloudstack-go/v2/cloudstack"
23-
"github.com/pkg/errors"
24-
corev1 "k8s.io/api/core/v1"
25-
conv "k8s.io/apimachinery/pkg/conversion"
2620
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"
27-
"sigs.k8s.io/cluster-api/api/v1beta1"
28-
"sigs.k8s.io/controller-runtime/pkg/client"
2921
"sigs.k8s.io/controller-runtime/pkg/conversion"
3022
)
3123

@@ -38,70 +30,3 @@ func (dst *CloudStackAffinityGroup) ConvertFrom(srcRaw conversion.Hub) error { /
3830
src := srcRaw.(*v1beta2.CloudStackAffinityGroup)
3931
return Convert_v1beta2_CloudStackAffinityGroup_To_v1beta1_CloudStackAffinityGroup(src, dst, nil)
4032
}
41-
42-
//nolint:golint,revive,stylecheck
43-
func Convert_v1beta1_CloudStackAffinityGroup_To_v1beta2_CloudStackAffinityGroup(in *CloudStackAffinityGroup, out *v1beta2.CloudStackAffinityGroup, s conv.Scope) error {
44-
out.ObjectMeta = in.ObjectMeta
45-
zoneID, zoneName, err := getAffinityGroupZone(in.ObjectMeta.Namespace, in.Spec.ID)
46-
if err != nil {
47-
return err
48-
}
49-
failureDomainName, err := GetDefaultFailureDomainName(in.ObjectMeta.Namespace, in.ObjectMeta.Labels[v1beta1.ClusterLabelName], zoneID, zoneName)
50-
if err != nil {
51-
return err
52-
}
53-
out.Spec = v1beta2.CloudStackAffinityGroupSpec{
54-
Type: in.Spec.Type,
55-
Name: in.Spec.Name,
56-
ID: in.Spec.ID,
57-
FailureDomainName: failureDomainName,
58-
}
59-
out.Status = v1beta2.CloudStackAffinityGroupStatus{
60-
Ready: in.Status.Ready,
61-
}
62-
return nil
63-
}
64-
65-
//nolint:golint,revive,stylecheck
66-
func Convert_v1beta2_CloudStackAffinityGroup_To_v1beta1_CloudStackAffinityGroup(in *v1beta2.CloudStackAffinityGroup, out *CloudStackAffinityGroup, s conv.Scope) error {
67-
out.ObjectMeta = in.ObjectMeta
68-
out.Spec = CloudStackAffinityGroupSpec{
69-
Type: in.Spec.Type,
70-
Name: in.Spec.Name,
71-
ID: in.Spec.ID,
72-
}
73-
out.Status = CloudStackAffinityGroupStatus{
74-
Ready: in.Status.Ready,
75-
}
76-
return nil
77-
}
78-
79-
func getAffinityGroupZone(namespace string, affinityGroupID string) (zoneID string, zoneName string, err error) {
80-
config, err := GetCloudStackConfig(namespace)
81-
if err != nil {
82-
return "", "", err
83-
}
84-
endpointCredentials := &corev1.Secret{}
85-
key := client.ObjectKey{Name: DefaultEndpointCredential, Namespace: namespace}
86-
if err := v1beta2.K8sClient.Get(context.TODO(), key, endpointCredentials); err != nil {
87-
return "", "", err
88-
}
89-
90-
csClient := cloudstack.NewAsyncClient(fmt.Sprint(config["api-url"]), fmt.Sprint(config["api-key"]), fmt.Sprint(config["secret-key"]), fmt.Sprint(config["verify-ssl"]) == "true")
91-
92-
parameters := csClient.VirtualMachine.NewListVirtualMachinesParams()
93-
parameters.SetAffinitygroupid(affinityGroupID)
94-
listVMResponse, err := csClient.VirtualMachine.ListVirtualMachines(parameters)
95-
if err != nil {
96-
return "", "", err
97-
}
98-
for _, vm := range listVMResponse.VirtualMachines {
99-
for _, ag := range vm.Affinitygroup {
100-
if ag.Id == affinityGroupID {
101-
return vm.Zoneid, vm.Zonename, nil
102-
}
103-
}
104-
}
105-
106-
return "", "", errors.Errorf("zone id and name could not found for affinity group id %s", affinityGroupID)
107-
}

api/v1beta1/zz_generated.conversion.go

Lines changed: 20 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/utils/base_reconciler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ func (r *ReconciliationRunner) NewChildObjectMeta(name string) metav1.ObjectMeta
489489
Name: strings.ToLower(name),
490490
Namespace: r.Request.Namespace,
491491
Labels: map[string]string{clusterv1.ClusterLabelName: r.CAPICluster.Name,
492-
infrav1.CloudStackClusterLabelName: r.CSCluster.Name},
492+
infrav1.CloudStackClusterLabelName: r.CAPICluster.Name},
493493
OwnerReferences: []metav1.OwnerReference{
494494
*metav1.NewControllerRef(r.ReconciliationSubject, ownerGVK),
495495
},

0 commit comments

Comments
 (0)