Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#126 from chuckha/update-imports
Browse files Browse the repository at this point in the history
Change imports from v1alpha1 to v1alpha2
  • Loading branch information
k8s-ci-robot authored Jul 25, 2019
2 parents 22e2ad5 + 3089ee0 commit 5a2bd2a
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 286 deletions.
4 changes: 2 additions & 2 deletions actuators/actuators.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/cluster-api-provider-docker/kind/actions"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
capiv1alpha2 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha2"
"sigs.k8s.io/kind/pkg/cluster/constants"
"sigs.k8s.io/kind/pkg/cluster/nodes"
)
Expand All @@ -35,7 +35,7 @@ const (
containerRunningStatus = "running"
)

func getRole(machine *clusterv1.Machine) string {
func getRole(machine *capiv1alpha2.Machine) string {
// Figure out what kind of node we're making
labels := machine.GetLabels()
setValue, ok := labels["set"]
Expand Down
6 changes: 3 additions & 3 deletions actuators/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package actuators
import (
"github.com/go-logr/logr"
"sigs.k8s.io/cluster-api-provider-docker/kind/actions"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
capiv1alpha2 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha2"
)

// Cluster defines a cluster actuator object
Expand All @@ -28,7 +28,7 @@ type Cluster struct {
}

// Reconcile setups an external load balancer for the cluster if needed
func (c *Cluster) Reconcile(cluster *clusterv1.Cluster) error {
func (c *Cluster) Reconcile(cluster *capiv1alpha2.Cluster) error {
c.Log.Info("Reconciling cluster", "cluster-namespace", cluster.Namespace, "cluster-name", cluster.Name)
elb, err := getExternalLoadBalancerNode(cluster.Name, c.Log)
if err != nil {
Expand All @@ -45,7 +45,7 @@ func (c *Cluster) Reconcile(cluster *clusterv1.Cluster) error {
}

// Delete can be used to delete a cluster
func (c *Cluster) Delete(cluster *clusterv1.Cluster) error {
func (c *Cluster) Delete(cluster *capiv1alpha2.Cluster) error {
c.Log.Info("Cluster delete is not implemented.")
return nil
}
59 changes: 15 additions & 44 deletions actuators/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@ package actuators

import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/types"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"sigs.k8s.io/cluster-api-provider-docker/kind/actions"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
"sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/typed/cluster/v1alpha1"
capierror "sigs.k8s.io/cluster-api/pkg/controller/error"
"sigs.k8s.io/controller-runtime/pkg/patch"
capiv1alpha2 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha2"
"sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/typed/cluster/v1alpha2"
capierror "sigs.k8s.io/cluster-api/pkg/errors"
"sigs.k8s.io/kind/pkg/cluster"
"sigs.k8s.io/kind/pkg/cluster/constants"
"sigs.k8s.io/kind/pkg/cluster/nodes"
Expand All @@ -44,14 +41,14 @@ const (
// Machine defines a machine actuator type
type Machine struct {
Core corev1.CoreV1Interface
ClusterAPI v1alpha1.ClusterV1alpha1Interface
ClusterAPI v1alpha2.ClusterV1alpha2Interface
Log logr.Logger
}

// Create creates a machine for a given cluster
// Note: have to print all the errors because cluster-api swallows them
func (m *Machine) Create(ctx context.Context, c *clusterv1.Cluster, machine *clusterv1.Machine) error {
old := machine.DeepCopy()
func (m *Machine) Create(ctx context.Context, c *capiv1alpha2.Cluster, machine *capiv1alpha2.Machine) error {
_ = machine.DeepCopy()
m.Log.Info("Creating a machine for cluster", "cluster-name", c.Name)
clusterExists, err := cluster.IsKnown(c.Name)
if err != nil {
Expand All @@ -75,14 +72,14 @@ func (m *Machine) Create(ctx context.Context, c *clusterv1.Cluster, machine *clu
if setValue == clusterAPIControlPlaneSetLabel {
if len(controlPlanes) > 0 {
m.Log.Info("Adding a control plane")
controlPlaneNode, err := actions.AddControlPlane(c.Name, machine.GetName(), machine.Spec.Versions.ControlPlane)
controlPlaneNode, err := actions.AddControlPlane(c.Name, machine.GetName(), *machine.Spec.Version)
if err != nil {
m.Log.Error(err, "Error adding control plane")
return err
}
providerID := actions.ProviderID(controlPlaneNode.Name())
machine.Spec.ProviderID = &providerID
return m.save(old, machine)
return nil
}

m.Log.Info("Creating a brand new cluster")
Expand All @@ -96,18 +93,15 @@ func (m *Machine) Create(ctx context.Context, c *clusterv1.Cluster, machine *clu
m.Log.Error(err, "Error getting node IP address")
return err
}
controlPlaneNode, err := actions.CreateControlPlane(c.Name, machine.GetName(), lbipv4, machine.Spec.Versions.ControlPlane, nil)
controlPlaneNode, err := actions.CreateControlPlane(c.Name, machine.GetName(), lbipv4, *machine.Spec.Version, nil)
if err != nil {
m.Log.Error(err, "Error creating control plane")
return err
}
// set the machine's providerID
providerID := actions.ProviderID(controlPlaneNode.Name())
machine.Spec.ProviderID = &providerID
if err := m.save(old, machine); err != nil {
m.Log.Error(err, "Error setting machine's provider ID")
return err
}

s, err := kubeconfigToSecret(c.Name, c.Namespace)
if err != nil {
m.Log.Error(err, "Error converting kubeconfig to a secret")
Expand All @@ -128,18 +122,18 @@ func (m *Machine) Create(ctx context.Context, c *clusterv1.Cluster, machine *clu
}

m.Log.Info("Creating a new worker node")
worker, err := actions.AddWorker(c.Name, machine.GetName(), machine.Spec.Versions.Kubelet)
worker, err := actions.AddWorker(c.Name, machine.GetName(), *machine.Spec.Version)
if err != nil {
m.Log.Error(err, "Error creating new worker node")
return err
}
providerID := actions.ProviderID(worker.Name())
machine.Spec.ProviderID = &providerID
return m.save(old, machine)
return nil
}

// Delete returns nil when the machine no longer exists or when a successful delete has happened.
func (m *Machine) Delete(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine) error {
func (m *Machine) Delete(ctx context.Context, cluster *capiv1alpha2.Cluster, machine *capiv1alpha2.Machine) error {
exists, err := m.Exists(ctx, cluster, machine)
if err != nil {
return err
Expand All @@ -157,13 +151,13 @@ func (m *Machine) Delete(ctx context.Context, cluster *clusterv1.Cluster, machin
}

// Update updates a machine
func (m *Machine) Update(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine) error {
func (m *Machine) Update(ctx context.Context, cluster *capiv1alpha2.Cluster, machine *capiv1alpha2.Machine) error {
m.Log.Info("Update machine is not implemented yet")
return nil
}

// Exists returns true if a machine exists in the cluster
func (m *Machine) Exists(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine) (bool, error) {
func (m *Machine) Exists(ctx context.Context, cluster *capiv1alpha2.Cluster, machine *capiv1alpha2.Machine) (bool, error) {
if machine.Spec.ProviderID != nil {
return true, nil
}
Expand All @@ -185,29 +179,6 @@ func (m *Machine) Exists(ctx context.Context, cluster *clusterv1.Cluster, machin
}

// patches the object and saves the status.
func (m *Machine) save(oldMachine, newMachine *clusterv1.Machine) error {
m.Log.Info("updating machine")
p, err := patch.NewJSONPatch(oldMachine, newMachine)
if err != nil {
m.Log.Error(err, "Error updating machine")
return err
}
m.Log.Info("Patches for machine", "patches", p)
if len(p) != 0 {
pb, err := json.MarshalIndent(p, "", " ")
if err != nil {
m.Log.Error(err, "Error marshalling machine")
return err
}
newMachine, err = m.ClusterAPI.Machines(oldMachine.Namespace).Patch(newMachine.Name, types.JSONPatchType, pb)
if err != nil {
m.Log.Error(err, "Error patching machine")
return err
}
m.Log.Info("updated machine")
}
return nil
}

// CAPIroleToKindRole converts a CAPI role to kind role
// TODO there is a better way to do this.
Expand Down
111 changes: 0 additions & 111 deletions cmd/capd-manager/main.go

This file was deleted.

46 changes: 8 additions & 38 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,14 @@ module sigs.k8s.io/cluster-api-provider-docker
go 1.12

require (
github.com/appscode/jsonpatch v0.0.0-20190108182946-7c0e3b262f30 // indirect
github.com/go-logr/logr v0.1.0
github.com/go-logr/zapr v0.1.1 // indirect
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
github.com/google/btree v1.0.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/pborman/uuid v1.2.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.8.0
github.com/prometheus/client_golang v0.9.4 // indirect
go.uber.org/atomic v1.4.0 // indirect
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.10.0 // indirect
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect
golang.org/x/net v0.0.0-20190628185345-da137c7871d7 // indirect
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect
golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542 // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
k8s.io/api v0.0.0-20190703205437-39734b2a72fe
k8s.io/apiextensions-apiserver v0.0.0-20181213153335-0fe22c71c476 // indirect
k8s.io/apimachinery v0.0.0-20190703205208-4cfb76a8bf76
k8s.io/client-go v11.0.0+incompatible
k8s.io/cluster-bootstrap v0.0.0-20181213155137-5f9271efc2e7 // indirect
k8s.io/klog v0.3.0
k8s.io/kubernetes v1.13.1
sigs.k8s.io/cluster-api v0.0.0-20190607141803-aacb0c613ffb
sigs.k8s.io/controller-runtime v0.1.10
github.com/pkg/errors v0.8.1
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
k8s.io/apimachinery v0.0.0-20190404173353-6a84e37a896d
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
k8s.io/cluster-bootstrap v0.0.0-20190516232516-d7d78ab2cfe7 // indirect
k8s.io/kubernetes v1.14.2
sigs.k8s.io/cluster-api v0.0.0-20190725170330-835ee872f98d
sigs.k8s.io/controller-runtime v0.2.0-beta.4
sigs.k8s.io/kind v0.4.0
sigs.k8s.io/testing_frameworks v0.1.1 // indirect
)

replace (
k8s.io/api => k8s.io/api v0.0.0-20181213150558-05914d821849
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20181127025237-2b1284ed4c93
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20190704050804-bd8686edbd81
k8s.io/client-go => k8s.io/client-go v10.0.0+incompatible
k8s.io/kubernetes => k8s.io/kubernetes v1.13.1
)
Loading

0 comments on commit 5a2bd2a

Please sign in to comment.