Skip to content

Commit efdb3e2

Browse files
Add GenericProvider interface to API objects
Signed-off-by: Danil Grigorev <[email protected]>
1 parent d254cf7 commit efdb3e2

File tree

8 files changed

+347
-51
lines changed

8 files changed

+347
-51
lines changed

api/v1alpha2/addonprovider_wrapper.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright 2023 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 v1alpha2
18+
19+
import (
20+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
21+
)
22+
23+
var _ GenericProvider = &AddonProvider{}
24+
25+
func (b *AddonProvider) GetConditions() clusterv1.Conditions {
26+
return b.Status.Conditions
27+
}
28+
29+
func (b *AddonProvider) SetConditions(conditions clusterv1.Conditions) {
30+
b.Status.Conditions = conditions
31+
}
32+
33+
func (b *AddonProvider) GetSpec() ProviderSpec {
34+
return b.Spec.ProviderSpec
35+
}
36+
37+
func (b *AddonProvider) SetSpec(in ProviderSpec) {
38+
b.Spec.ProviderSpec = in
39+
}
40+
41+
func (b *AddonProvider) GetStatus() ProviderStatus {
42+
return b.Status.ProviderStatus
43+
}
44+
45+
func (b *AddonProvider) SetStatus(in ProviderStatus) {
46+
b.Status.ProviderStatus = in
47+
}
48+
49+
func (b *AddonProvider) GetType() string {
50+
return "addon"
51+
}
52+
53+
func (b *AddonProviderList) GetItems() []GenericProvider {
54+
providers := []GenericProvider{}
55+
56+
for index := range b.Items {
57+
providers = append(providers, &b.Items[index])
58+
}
59+
60+
return providers
61+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright 2021 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 v1alpha2
18+
19+
import (
20+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
21+
)
22+
23+
var _ GenericProvider = &BootstrapProvider{}
24+
25+
func (b *BootstrapProvider) GetConditions() clusterv1.Conditions {
26+
return b.Status.Conditions
27+
}
28+
29+
func (b *BootstrapProvider) SetConditions(conditions clusterv1.Conditions) {
30+
b.Status.Conditions = conditions
31+
}
32+
33+
func (b *BootstrapProvider) GetSpec() ProviderSpec {
34+
return b.Spec.ProviderSpec
35+
}
36+
37+
func (b *BootstrapProvider) SetSpec(in ProviderSpec) {
38+
b.Spec.ProviderSpec = in
39+
}
40+
41+
func (b *BootstrapProvider) GetStatus() ProviderStatus {
42+
return b.Status.ProviderStatus
43+
}
44+
45+
func (b *BootstrapProvider) SetStatus(in ProviderStatus) {
46+
b.Status.ProviderStatus = in
47+
}
48+
49+
func (b *BootstrapProvider) GetType() string {
50+
return "bootstrap"
51+
}
52+
53+
func (b *BootstrapProviderList) GetItems() []GenericProvider {
54+
providers := []GenericProvider{}
55+
56+
for index := range b.Items {
57+
providers = append(providers, &b.Items[index])
58+
}
59+
60+
return providers
61+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright 2021 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 v1alpha2
18+
19+
import (
20+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
21+
)
22+
23+
var _ GenericProvider = &ControlPlaneProvider{}
24+
25+
func (c *ControlPlaneProvider) GetConditions() clusterv1.Conditions {
26+
return c.Status.Conditions
27+
}
28+
29+
func (c *ControlPlaneProvider) SetConditions(conditions clusterv1.Conditions) {
30+
c.Status.Conditions = conditions
31+
}
32+
33+
func (c *ControlPlaneProvider) GetSpec() ProviderSpec {
34+
return c.Spec.ProviderSpec
35+
}
36+
37+
func (c *ControlPlaneProvider) SetSpec(in ProviderSpec) {
38+
c.Spec.ProviderSpec = in
39+
}
40+
41+
func (c *ControlPlaneProvider) GetStatus() ProviderStatus {
42+
return c.Status.ProviderStatus
43+
}
44+
45+
func (c *ControlPlaneProvider) SetStatus(in ProviderStatus) {
46+
c.Status.ProviderStatus = in
47+
}
48+
49+
func (c *ControlPlaneProvider) GetType() string {
50+
return "controlplane"
51+
}
52+
53+
func (c *ControlPlaneProviderList) GetItems() []GenericProvider {
54+
providers := make([]GenericProvider, len(c.Items))
55+
56+
for index := range c.Items {
57+
providers[index] = &c.Items[index]
58+
}
59+
60+
return providers
61+
}

api/v1alpha2/coreprovider_wrapper.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright 2021 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 v1alpha2
18+
19+
import (
20+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
21+
)
22+
23+
var _ GenericProvider = &CoreProvider{}
24+
25+
func (c *CoreProvider) GetConditions() clusterv1.Conditions {
26+
return c.Status.Conditions
27+
}
28+
29+
func (c *CoreProvider) SetConditions(conditions clusterv1.Conditions) {
30+
c.Status.Conditions = conditions
31+
}
32+
33+
func (c *CoreProvider) GetSpec() ProviderSpec {
34+
return c.Spec.ProviderSpec
35+
}
36+
37+
func (c *CoreProvider) SetSpec(in ProviderSpec) {
38+
c.Spec.ProviderSpec = in
39+
}
40+
41+
func (c *CoreProvider) GetStatus() ProviderStatus {
42+
return c.Status.ProviderStatus
43+
}
44+
45+
func (c *CoreProvider) SetStatus(in ProviderStatus) {
46+
c.Status.ProviderStatus = in
47+
}
48+
49+
func (c *CoreProvider) GetType() string {
50+
return "core"
51+
}
52+
53+
func (c *CoreProviderList) GetItems() []GenericProvider {
54+
providers := make([]GenericProvider, len(c.Items))
55+
56+
for index := range c.Items {
57+
providers[index] = &c.Items[index]
58+
}
59+
60+
return providers
61+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright 2021 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 v1alpha2
18+
19+
import (
20+
"sigs.k8s.io/cluster-api/util/conditions"
21+
)
22+
23+
// GenericProvider interface describes operations applicable to the provider type.
24+
//
25+
// +kubebuilder:object:generate=false
26+
type GenericProvider interface {
27+
conditions.Setter
28+
GetSpec() ProviderSpec
29+
SetSpec(in ProviderSpec)
30+
GetStatus() ProviderStatus
31+
SetStatus(in ProviderStatus)
32+
GetType() string
33+
}
34+
35+
// GenericProviderList interface describes operations applicable to the provider list type.
36+
//
37+
// +kubebuilder:object:generate=false
38+
type GenericProviderList interface {
39+
GetItems() []GenericProvider
40+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright 2021 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 v1alpha2
18+
19+
import (
20+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
21+
)
22+
23+
var _ GenericProvider = &InfrastructureProvider{}
24+
25+
func (c *InfrastructureProvider) GetConditions() clusterv1.Conditions {
26+
return c.Status.Conditions
27+
}
28+
29+
func (c *InfrastructureProvider) SetConditions(conditions clusterv1.Conditions) {
30+
c.Status.Conditions = conditions
31+
}
32+
33+
func (c *InfrastructureProvider) GetSpec() ProviderSpec {
34+
return c.Spec.ProviderSpec
35+
}
36+
37+
func (c *InfrastructureProvider) SetSpec(in ProviderSpec) {
38+
c.Spec.ProviderSpec = in
39+
}
40+
41+
func (c *InfrastructureProvider) GetStatus() ProviderStatus {
42+
return c.Status.ProviderStatus
43+
}
44+
45+
func (c *InfrastructureProvider) SetStatus(in ProviderStatus) {
46+
c.Status.ProviderStatus = in
47+
}
48+
49+
func (c *InfrastructureProvider) GetType() string {
50+
return "infrastructure"
51+
}
52+
53+
func (c *InfrastructureProviderList) GetItems() []GenericProvider {
54+
providers := make([]GenericProvider, len(c.Items))
55+
56+
for index := range c.Items {
57+
providers[index] = &c.Items[index]
58+
}
59+
60+
return providers
61+
}

controllers/alias.go

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)