Skip to content

Commit

Permalink
Merge pull request #341 from Danil-Grigorev/provider-interface
Browse files Browse the repository at this point in the history
🌱  Move generic provider interface to API package
  • Loading branch information
k8s-ci-robot authored Dec 13, 2023
2 parents d6303a0 + 93332d8 commit 5772077
Show file tree
Hide file tree
Showing 28 changed files with 847 additions and 1,184 deletions.
61 changes: 61 additions & 0 deletions api/v1alpha2/addonprovider_wrapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright 2023 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.
*/

package v1alpha2

import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

var _ GenericProvider = &AddonProvider{}

func (b *AddonProvider) GetConditions() clusterv1.Conditions {
return b.Status.Conditions
}

func (b *AddonProvider) SetConditions(conditions clusterv1.Conditions) {
b.Status.Conditions = conditions
}

func (b *AddonProvider) GetSpec() ProviderSpec {
return b.Spec.ProviderSpec
}

func (b *AddonProvider) SetSpec(in ProviderSpec) {
b.Spec.ProviderSpec = in
}

func (b *AddonProvider) GetStatus() ProviderStatus {
return b.Status.ProviderStatus
}

func (b *AddonProvider) SetStatus(in ProviderStatus) {
b.Status.ProviderStatus = in
}

func (b *AddonProvider) GetType() string {
return "addon"
}

func (b *AddonProviderList) GetItems() []GenericProvider {
providers := []GenericProvider{}

for index := range b.Items {
providers = append(providers, &b.Items[index])
}

return providers
}
61 changes: 61 additions & 0 deletions api/v1alpha2/bootstrapprovider_wrapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright 2021 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.
*/

package v1alpha2

import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

var _ GenericProvider = &BootstrapProvider{}

func (b *BootstrapProvider) GetConditions() clusterv1.Conditions {
return b.Status.Conditions
}

func (b *BootstrapProvider) SetConditions(conditions clusterv1.Conditions) {
b.Status.Conditions = conditions
}

func (b *BootstrapProvider) GetSpec() ProviderSpec {
return b.Spec.ProviderSpec
}

func (b *BootstrapProvider) SetSpec(in ProviderSpec) {
b.Spec.ProviderSpec = in
}

func (b *BootstrapProvider) GetStatus() ProviderStatus {
return b.Status.ProviderStatus
}

func (b *BootstrapProvider) SetStatus(in ProviderStatus) {
b.Status.ProviderStatus = in
}

func (b *BootstrapProvider) GetType() string {
return "bootstrap"
}

func (b *BootstrapProviderList) GetItems() []GenericProvider {
providers := []GenericProvider{}

for index := range b.Items {
providers = append(providers, &b.Items[index])
}

return providers
}
61 changes: 61 additions & 0 deletions api/v1alpha2/controlplaneprovider_wrapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright 2021 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.
*/

package v1alpha2

import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

var _ GenericProvider = &ControlPlaneProvider{}

func (c *ControlPlaneProvider) GetConditions() clusterv1.Conditions {
return c.Status.Conditions
}

func (c *ControlPlaneProvider) SetConditions(conditions clusterv1.Conditions) {
c.Status.Conditions = conditions
}

func (c *ControlPlaneProvider) GetSpec() ProviderSpec {
return c.Spec.ProviderSpec
}

func (c *ControlPlaneProvider) SetSpec(in ProviderSpec) {
c.Spec.ProviderSpec = in
}

func (c *ControlPlaneProvider) GetStatus() ProviderStatus {
return c.Status.ProviderStatus
}

func (c *ControlPlaneProvider) SetStatus(in ProviderStatus) {
c.Status.ProviderStatus = in
}

func (c *ControlPlaneProvider) GetType() string {
return "controlplane"
}

func (c *ControlPlaneProviderList) GetItems() []GenericProvider {
providers := make([]GenericProvider, len(c.Items))

for index := range c.Items {
providers[index] = &c.Items[index]
}

return providers
}
61 changes: 61 additions & 0 deletions api/v1alpha2/coreprovider_wrapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright 2021 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.
*/

package v1alpha2

import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

var _ GenericProvider = &CoreProvider{}

func (c *CoreProvider) GetConditions() clusterv1.Conditions {
return c.Status.Conditions
}

func (c *CoreProvider) SetConditions(conditions clusterv1.Conditions) {
c.Status.Conditions = conditions
}

func (c *CoreProvider) GetSpec() ProviderSpec {
return c.Spec.ProviderSpec
}

func (c *CoreProvider) SetSpec(in ProviderSpec) {
c.Spec.ProviderSpec = in
}

func (c *CoreProvider) GetStatus() ProviderStatus {
return c.Status.ProviderStatus
}

func (c *CoreProvider) SetStatus(in ProviderStatus) {
c.Status.ProviderStatus = in
}

func (c *CoreProvider) GetType() string {
return "core"
}

func (c *CoreProviderList) GetItems() []GenericProvider {
providers := make([]GenericProvider, len(c.Items))

for index := range c.Items {
providers[index] = &c.Items[index]
}

return providers
}
40 changes: 40 additions & 0 deletions api/v1alpha2/genericprovider_interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright 2021 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.
*/

package v1alpha2

import (
"sigs.k8s.io/cluster-api/util/conditions"
)

// GenericProvider interface describes operations applicable to the provider type.
//
// +kubebuilder:object:generate=false
type GenericProvider interface {
conditions.Setter
GetSpec() ProviderSpec
SetSpec(in ProviderSpec)
GetStatus() ProviderStatus
SetStatus(in ProviderStatus)
GetType() string
}

// GenericProviderList interface describes operations applicable to the provider list type.
//
// +kubebuilder:object:generate=false
type GenericProviderList interface {
GetItems() []GenericProvider
}
61 changes: 61 additions & 0 deletions api/v1alpha2/infrastructureprovider_wrapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright 2021 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.
*/

package v1alpha2

import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

var _ GenericProvider = &InfrastructureProvider{}

func (c *InfrastructureProvider) GetConditions() clusterv1.Conditions {
return c.Status.Conditions
}

func (c *InfrastructureProvider) SetConditions(conditions clusterv1.Conditions) {
c.Status.Conditions = conditions
}

func (c *InfrastructureProvider) GetSpec() ProviderSpec {
return c.Spec.ProviderSpec
}

func (c *InfrastructureProvider) SetSpec(in ProviderSpec) {
c.Spec.ProviderSpec = in
}

func (c *InfrastructureProvider) GetStatus() ProviderStatus {
return c.Status.ProviderStatus
}

func (c *InfrastructureProvider) SetStatus(in ProviderStatus) {
c.Status.ProviderStatus = in
}

func (c *InfrastructureProvider) GetType() string {
return "infrastructure"
}

func (c *InfrastructureProviderList) GetItems() []GenericProvider {
providers := make([]GenericProvider, len(c.Items))

for index := range c.Items {
providers[index] = &c.Items[index]
}

return providers
}
2 changes: 1 addition & 1 deletion api/v1alpha2/provider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ type DeploymentSpec struct {

// List of containers specified in the Deployment
// +optional
Containers []ContainerSpec `json:"containers"`
Containers []ContainerSpec `json:"containers,omitempty"`

// If specified, the pod's service account
// +optional
Expand Down
4 changes: 2 additions & 2 deletions cmd/plugin/cmd/upgrade_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/spf13/cobra"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

"sigs.k8s.io/cluster-api-operator/internal/controller/genericprovider"
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
)

type upgradePlanOptions struct {
Expand All @@ -50,7 +50,7 @@ type upgradePlan struct {

// upgradeItem defines a possible upgrade target for a provider in the management cluster.
type upgradeItem struct {
genericprovider.GenericProvider
operatorv1.GenericProvider
NextVersion string
}

Expand Down
Loading

0 comments on commit 5772077

Please sign in to comment.