Skip to content
This repository was archived by the owner on Sep 24, 2021. It is now read-only.

Commit 087f5c1

Browse files
author
Amy Chen
committed
small refactor for actuator folder
1 parent b2324ba commit 087f5c1

File tree

2 files changed

+55
-30
lines changed

2 files changed

+55
-30
lines changed

actuators/actuators.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,6 @@ func getRole(machine *clusterv1.Machine) string {
3939
return setValue
4040
}
4141

42-
// Cluster defines a cluster actuator object
43-
type Cluster struct{}
44-
45-
// NewClusterActuator returns a new cluster actuator object
46-
func NewClusterActuator() *Cluster {
47-
return &Cluster{}
48-
}
49-
50-
// Reconcile setups an external load balancer for the cluster if needed
51-
func (c *Cluster) Reconcile(cluster *clusterv1.Cluster) error {
52-
elb, err := getExternalLoadBalancerNode(cluster.Name)
53-
if err != nil {
54-
fmt.Printf("%+v\n", err)
55-
return err
56-
}
57-
if elb != nil {
58-
fmt.Println("External Load Balancer already exists. Nothing to do for this cluster.")
59-
return nil
60-
}
61-
fmt.Printf("The cluster named %q has been created! Setting up some infrastructure.\n", cluster.Name)
62-
_, err = actions.SetUpLoadBalancer(cluster.Name)
63-
return err
64-
}
65-
6642
func getExternalLoadBalancerNode(clusterName string) (*nodes.Node, error) {
6743
elb, err := nodes.List(
6844
fmt.Sprintf("label=%s=%s", constants.NodeRoleKey, constants.ExternalLoadBalancerNodeRoleValue),
@@ -80,12 +56,6 @@ func getExternalLoadBalancerNode(clusterName string) (*nodes.Node, error) {
8056
return &elb[0], nil
8157
}
8258

83-
// Delete can be used to delete a cluster
84-
func (c *Cluster) Delete(cluster *clusterv1.Cluster) error {
85-
fmt.Println("Cluster delete is not implemented.")
86-
return nil
87-
}
88-
8959
func kubeconfigToSecret(clusterName, namespace string) (*v1.Secret, error) {
9060
// open kubeconfig file
9161
data, err := ioutil.ReadFile(actions.KubeConfigPath(clusterName))

actuators/cluster.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2019 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 actuators
18+
19+
import (
20+
"fmt"
21+
22+
"sigs.k8s.io/cluster-api-provider-docker/kind/actions"
23+
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
24+
)
25+
26+
// Cluster defines a cluster actuator object
27+
type Cluster struct {
28+
}
29+
30+
// NewClusterActuator returns a new cluster actuator object
31+
func NewClusterActuator() *Cluster {
32+
return &Cluster{}
33+
}
34+
35+
// Reconcile setups an external load balancer for the cluster if needed
36+
func (c *Cluster) Reconcile(cluster *clusterv1.Cluster) error {
37+
elb, err := getExternalLoadBalancerNode(cluster.Name)
38+
if err != nil {
39+
fmt.Printf("%+v\n", err)
40+
return err
41+
}
42+
if elb != nil {
43+
fmt.Println("External Load Balancer already exists. Nothing to do for this cluster.")
44+
return nil
45+
}
46+
fmt.Printf("The cluster named %q has been created! Setting up some infrastructure.\n", cluster.Name)
47+
_, err = actions.SetUpLoadBalancer(cluster.Name)
48+
return err
49+
}
50+
51+
// Delete can be used to delete a cluster
52+
func (c *Cluster) Delete(cluster *clusterv1.Cluster) error {
53+
fmt.Println("Cluster delete is not implemented.")
54+
return nil
55+
}

0 commit comments

Comments
 (0)