Skip to content

Commit

Permalink
feat: Upgrade cluster.x-k8s.io/v1alpha4 to `cluster.x-k8s.io/v1beta…
Browse files Browse the repository at this point in the history
…1` (harvester#5377)

* feat(go.mod): remove cluster-api v1alpha4
* feat(generate): bump cluster-api to v1beta1
* feat: bump cluster-api to v1beta1

---------

Signed-off-by: PoAn Yang <[email protected]>
  • Loading branch information
FrankYang0529 authored May 22, 2024
1 parent fe079f3 commit 331d2a3
Show file tree
Hide file tree
Showing 55 changed files with 264 additions and 7,760 deletions.
27 changes: 0 additions & 27 deletions go.sum

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pkg/codegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
networkingv1 "k8s.io/api/networking/v1"
storagev1 "k8s.io/api/storage/v1"
kubevirtv1 "kubevirt.io/api/core/v1"
capi "sigs.k8s.io/cluster-api/api/v1alpha4"
capi "sigs.k8s.io/cluster-api/api/v1beta1"

harvesterv1 "github.com/harvester/harvester/pkg/apis/harvesterhci.io/v1beta1"
)
Expand Down Expand Up @@ -190,14 +190,14 @@ func nadControllerInterfaceRefactor() {

// capiWorkaround replaces the variable `SchemeGroupVersion` with `GroupVersion` in clusters.cluster.x-k8s.io client because
// `SchemeGroupVersion` is not declared in the vendor package but wrangler uses it.
// https://github.com/kubernetes-sigs/cluster-api/blob/56f9e9db7a9e9ca625ffe4bdc1e5e93a14d5e96c/api/v1alpha4/groupversion_info.go#L29
// https://github.com/kubernetes-sigs/cluster-api/blob/56f9e9db7a9e9ca625ffe4bdc1e5e93a14d5e96c/api/v1beta1/groupversion_info.go#L29
func capiWorkaround() {
absPath, _ := filepath.Abs("pkg/generated/clientset/versioned/typed/cluster.x-k8s.io/v1alpha4/cluster.x-k8s.io_client.go")
absPath, _ := filepath.Abs("pkg/generated/clientset/versioned/typed/cluster.x-k8s.io/v1beta1/cluster.x-k8s.io_client.go")
input, err := ioutil.ReadFile(absPath)
if err != nil {
logrus.Fatalf("failed to read the clusters.cluster.x-k8s.io client file: %v", err)
}
output := bytes.Replace(input, []byte("v1alpha4.SchemeGroupVersion"), []byte("v1alpha4.GroupVersion"), -1)
output := bytes.Replace(input, []byte("v1beta1.SchemeGroupVersion"), []byte("v1beta1.GroupVersion"), -1)

if err = ioutil.WriteFile(absPath, output, 0644); err != nil {
logrus.Fatalf("failed to update the clusters.cluster.x-k8s.io client file: %v", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package machine
import (
"context"

clusterv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4"
clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

"github.com/harvester/harvester/pkg/config"
ctlclusterv1 "github.com/harvester/harvester/pkg/generated/controllers/cluster.x-k8s.io/v1alpha4"
ctlclusterv1 "github.com/harvester/harvester/pkg/generated/controllers/cluster.x-k8s.io/v1beta1"
"github.com/harvester/harvester/pkg/util"
)

Expand All @@ -23,7 +22,7 @@ type machineControlPlaneHandler struct {

// machineControlPlaneHandler registers a controller to sync labels
func ControlPlaneRegister(ctx context.Context, management *config.Management, _ config.Options) error {
machines := management.ClusterFactory.Cluster().V1alpha4().Machine()
machines := management.ClusterFactory.Cluster().V1beta1().Machine()
handler := &machineControlPlaneHandler{
machineClient: machines,
}
Expand All @@ -33,15 +32,15 @@ func ControlPlaneRegister(ctx context.Context, management *config.Management, _
return nil
}

func (h *machineControlPlaneHandler) OnMachineChanged(_ string, machine *clusterv1alpha4.Machine) (*clusterv1alpha4.Machine, error) {
func (h *machineControlPlaneHandler) OnMachineChanged(_ string, machine *clusterv1.Machine) (*clusterv1.Machine, error) {
if machine == nil || machine.DeletionTimestamp != nil || machine.Labels == nil {
return machine, nil
}

if v1, ok := machine.Labels[util.RKEControlPlaneRoleLabel]; ok && v1 == "true" {
if v2, ok := machine.Labels[clusterv1beta1.MachineControlPlaneLabel]; !ok || v2 != "true" {
if v2, ok := machine.Labels[clusterv1.MachineControlPlaneLabel]; !ok || v2 != "true" {
machineCopy := machine.DeepCopy()
machineCopy.Labels[clusterv1beta1.MachineControlPlaneLabel] = "true"
machineCopy.Labels[clusterv1.MachineControlPlaneLabel] = "true"
return h.machineClient.Update(machineCopy)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/master/node/node_remove_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

"github.com/harvester/harvester/pkg/config"
ctlclusterv1 "github.com/harvester/harvester/pkg/generated/controllers/cluster.x-k8s.io/v1alpha4"
ctlclusterv1 "github.com/harvester/harvester/pkg/generated/controllers/cluster.x-k8s.io/v1beta1"
"github.com/harvester/harvester/pkg/util"
)

Expand All @@ -26,7 +26,7 @@ type nodeRemoveHandler struct {
// RemoveRegister registers a controller to remove machine when node is removed
func RemoveRegister(ctx context.Context, management *config.Management, _ config.Options) error {
nodes := management.CoreFactory.Core().V1().Node()
machineClient := management.ClusterFactory.Cluster().V1alpha4().Machine()
machineClient := management.ClusterFactory.Cluster().V1beta1().Machine()
handler := &nodeRemoveHandler{
machineClient: machineClient,
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/master/upgrade/job_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
capiv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

harvesterv1 "github.com/harvester/harvester/pkg/apis/harvesterhci.io/v1beta1"
clusterv1ctl "github.com/harvester/harvester/pkg/generated/controllers/cluster.x-k8s.io/v1alpha4"
ctlclusterv1 "github.com/harvester/harvester/pkg/generated/controllers/cluster.x-k8s.io/v1beta1"
ctlharvesterv1 "github.com/harvester/harvester/pkg/generated/controllers/harvesterhci.io/v1beta1"
upgradev1 "github.com/harvester/harvester/pkg/generated/controllers/upgrade.cattle.io/v1"
)
Expand Down Expand Up @@ -54,7 +54,7 @@ type jobHandler struct {
upgradeClient ctlharvesterv1.UpgradeClient
upgradeCache ctlharvesterv1.UpgradeCache

machineCache clusterv1ctl.MachineCache
machineCache ctlclusterv1.MachineCache
secretClient ctlcorev1.SecretClient
nodeClient ctlcorev1.NodeClient
nodeCache ctlcorev1.NodeCache
Expand Down Expand Up @@ -99,7 +99,7 @@ func (h *jobHandler) syncNodeJob(job *batchv1.Job) (*batchv1.Job, error) {
return job, nil
}

machineName, ok := node.Annotations[capiv1alpha4.MachineAnnotation]
machineName, ok := node.Annotations[clusterv1.MachineAnnotation]
if !ok {
return job, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/master/upgrade/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
capiv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

ctlharvesterv1 "github.com/harvester/harvester/pkg/generated/controllers/harvesterhci.io/v1beta1"
)
Expand Down Expand Up @@ -59,7 +59,7 @@ func (h *nodeHandler) OnChanged(_ string, node *corev1.Node) (*corev1.Node, erro
return node, nil
}

machineName, ok := node.Annotations[capiv1alpha4.MachineAnnotation]
machineName, ok := node.Annotations[clusterv1.MachineAnnotation]
if !ok {
return node, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/master/upgrade/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Register(ctx context.Context, management *config.Management, options config
services := management.CoreFactory.Core().V1().Service()
namespaces := management.CoreFactory.Core().V1().Namespace()
clusters := management.ProvisioningFactory.Provisioning().V1().Cluster()
machines := management.ClusterFactory.Cluster().V1alpha4().Machine()
machines := management.ClusterFactory.Cluster().V1beta1().Machine()
secrets := management.CoreFactory.Core().V1().Secret()
pvcs := management.CoreFactory.Core().V1().PersistentVolumeClaim()
lhSettings := management.LonghornFactory.Longhorn().V1beta2().Setting()
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/master/upgrade/secret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"k8s.io/apimachinery/pkg/labels"

harvesterv1 "github.com/harvester/harvester/pkg/apis/harvesterhci.io/v1beta1"
clusterv1ctl "github.com/harvester/harvester/pkg/generated/controllers/cluster.x-k8s.io/v1alpha4"
ctlclusterv1 "github.com/harvester/harvester/pkg/generated/controllers/cluster.x-k8s.io/v1beta1"
ctlharvesterv1 "github.com/harvester/harvester/pkg/generated/controllers/harvesterhci.io/v1beta1"
)

Expand All @@ -27,7 +27,7 @@ type secretHandler struct {
upgradeCache ctlharvesterv1.UpgradeCache
jobClient jobV1.JobClient
jobCache jobV1.JobCache
machineCache clusterv1ctl.MachineCache
machineCache ctlclusterv1.MachineCache
}

func (h *secretHandler) OnChanged(_ string, secret *v1.Secret) (*v1.Secret, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/data/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
rkev1 "github.com/rancher/rancher/pkg/apis/rke.cattle.io/v1"
upgradev1 "github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1"
"k8s.io/client-go/rest"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

harvesterv1 "github.com/harvester/harvester/pkg/apis/harvesterhci.io/v1beta1"
"github.com/harvester/harvester/pkg/util/crd"
Expand Down
16 changes: 8 additions & 8 deletions pkg/generated/clientset/versioned/clientset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pkg/generated/clientset/versioned/fake/clientset_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/generated/clientset/versioned/fake/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/generated/clientset/versioned/scheme/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 331d2a3

Please sign in to comment.