Skip to content

Commit

Permalink
Conform folder struct and controller code to Go standard (kubernetes-…
Browse files Browse the repository at this point in the history
…sigs#83)

* Moved folders around to match standard go project structure

Created cmd and pkg as top level folder and moved folders around appropriately.  Fixed
up the makefiles and dockerfiles.

* Use Go standard for struct name for functions

Some leftover code from before this repo was under sig-vmware didn't
follow the go standard.  Fixed them.

Resolves kubernetes-sigs#81
  • Loading branch information
Loc Nguyen authored and k8s-ci-robot committed Oct 18, 2018
1 parent 2976b2f commit 10c76a3
Show file tree
Hide file tree
Showing 42 changed files with 222 additions and 222 deletions.
2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ required = [

[[constraint]]
name = "sigs.k8s.io/cluster-api"
branch = "master"
revision = "7db708b5df567c79e2e46f9c37cdbf001bef1302"

[[constraint]]
name = "k8s.io/code-generator"
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ generate: gendeepcopy
gendeepcopy:
go build -o $$GOPATH/bin/deepcopy-gen sigs.k8s.io/cluster-api-provider-vsphere/vendor/k8s.io/code-generator/cmd/deepcopy-gen
deepcopy-gen \
-i ./cloud/vsphere/vsphereproviderconfig,./cloud/vsphere/vsphereproviderconfig/v1alpha1 \
-i ./pkg/cloud/vsphere/vsphereproviderconfig,./pkg/cloud/vsphere/vsphereproviderconfig/v1alpha1 \
-O zz_generated.deepcopy \
-h boilerplate.go.txt

build: depend
CGO_ENABLED=0 go install -a -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-vsphere/cloud/vsphere/cmd/vsphere-machine-controller
CGO_ENABLED=0 go install -a -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-vsphere/cmd/vsphere-machine-controller

images: depend
$(MAKE) -C cloud/vsphere/cmd/vsphere-machine-controller image
$(MAKE) -C cmd/vsphere-machine-controller image

push: depend
$(MAKE) -C cloud/vsphere/cmd/vsphere-machine-controller push
$(MAKE) -C cmd/vsphere-machine-controller push

check: depend fmt vet

Expand Down
1 change: 0 additions & 1 deletion cloud/vsphere/cmd/vsphere-machine-controller/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions cmd/clusterctl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
clusterctl
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion clusterctl/main.go → cmd/clusterctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ limitations under the License.
package main

import (
_ "sigs.k8s.io/cluster-api-provider-vsphere/cloud/vsphere"
_ "sigs.k8s.io/cluster-api-provider-vsphere/pkg/cloud/vsphere"
"sigs.k8s.io/cluster-api/clusterctl/cmd"
)

Expand Down
1 change: 1 addition & 0 deletions cmd/vsphere-machine-controller/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
manager
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ WORKDIR /go/src/sigs.k8s.io/cluster-api-provider-vsphere
# This expects that the context passed to the docker build command is
# the cluster-api directory.
# e.g. docker build -t <tag> -f <this_Dockerfile> <path_to_cluster-api>
COPY . .
COPY . .

RUN CGO_ENABLED=0 GOOS=linux go install -a -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-vsphere/cloud/vsphere/cmd/vsphere-machine-controller
RUN CGO_ENABLED=0 GOOS=linux go install -a -ldflags '-extldflags "-static"' sigs.k8s.io/cluster-api-provider-vsphere/cmd/vsphere-machine-controller

# Final container
FROM debian:stretch-slim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ NAME = vsphere-machine-controller
TAG = 0.0.11

image:
docker build -t "$(PREFIX)/$(NAME):$(TAG)" -f ./Dockerfile ../../../..
docker build -t "$(PREFIX)/$(NAME):$(TAG)" -f ./Dockerfile ../..

push: image
docker push "$(PREFIX)/$(NAME):$(TAG)"
Expand All @@ -32,7 +32,7 @@ fix_gcs_permissions:
gsutil -m acl ch -r -u AllUsers:READ gs://artifacts.$(GCR_BUCKET).appspot.com

dev_image:
docker build -t "$(DEV_PREFIX)/$(NAME):$(TAG)-dev" -f ./Dockerfile ../../../..
docker build -t "$(DEV_PREFIX)/$(NAME):$(TAG)-dev" -f ./Dockerfile ../..

dev_push: dev_image
docker push "$(DEV_PREFIX)/$(NAME):$(TAG)-dev"
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/cluster-api-provider-vsphere/cloud/vsphere"
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/cloud/vsphere"
"sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset"
clusterapiclientsetscheme "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/scheme"
"sigs.k8s.io/cluster-api/pkg/controller/cluster"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/cluster-api-provider-vsphere/cloud/vsphere/constants"
vsphereutils "sigs.k8s.io/cluster-api-provider-vsphere/cloud/vsphere/utils"
vsphereconfig "sigs.k8s.io/cluster-api-provider-vsphere/cloud/vsphere/vsphereproviderconfig"
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/cloud/vsphere/constants"
vsphereutils "sigs.k8s.io/cluster-api-provider-vsphere/pkg/cloud/vsphere/utils"
vsphereconfig "sigs.k8s.io/cluster-api-provider-vsphere/pkg/cloud/vsphere/vsphereproviderconfig"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
clusterv1alpha1 "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/typed/cluster/v1alpha1"
v1alpha1 "sigs.k8s.io/cluster-api/pkg/client/informers_generated/externalversions/cluster/v1alpha1"
Expand All @@ -46,7 +46,7 @@ type ClusterActuator struct {
}

// Reconcile will create or update the cluster
func (vc *ClusterActuator) Reconcile(cluster *clusterv1.Cluster) error {
func (ca *ClusterActuator) Reconcile(cluster *clusterv1.Cluster) error {
glog.Infof("Attempting to reconcile cluster %s", cluster.ObjectMeta.Name)

// The generic workflow would be as follows:
Expand All @@ -57,7 +57,7 @@ func (vc *ClusterActuator) Reconcile(cluster *clusterv1.Cluster) error {
// In the absence of the lb creation, the logic would be to simply take the first master node
// and use that as the API endpoint for now.
if len(cluster.Status.APIEndpoints) == 0 {
err := vc.provisionLoadBalancer(cluster)
err := ca.provisionLoadBalancer(cluster)
if err != nil {
glog.Infof("Error could not provision the Load Balancer for the cluster: %s", err)
return err
Expand All @@ -67,33 +67,33 @@ func (vc *ClusterActuator) Reconcile(cluster *clusterv1.Cluster) error {
//return nil
}
// At this stage we are expecting the lb endpoint to be present in the final lb implementation
err := vc.ensureLoadBalancerMembers(cluster)
err := ca.ensureLoadBalancerMembers(cluster)
if err != nil {
glog.Infof("Error setting the Load Balancer members for the cluster: %s", err)
return err
}
// Check if the target kubernetes is ready or not, and update the ProviderStatus if change is detected
err = vc.updateK8sAPIStatus(cluster)
err = ca.updateK8sAPIStatus(cluster)
if err != nil {
return err
}
return nil
}

func (vc *ClusterActuator) updateK8sAPIStatus(cluster *clusterv1.Cluster) error {
currentClusterAPIStatus, err := vc.getClusterAPIStatus(cluster)
func (ca *ClusterActuator) updateK8sAPIStatus(cluster *clusterv1.Cluster) error {
currentClusterAPIStatus, err := ca.getClusterAPIStatus(cluster)
if err != nil {
return err
}
return vc.updateClusterAPIStatus(cluster, currentClusterAPIStatus)
return ca.updateClusterAPIStatus(cluster, currentClusterAPIStatus)
}

// fetchKubeConfig returns the cached copy of the Kubeconfig in the secrets for the target cluster
// In case the secret does not exist, then it fetches from the target master node and caches it for
func (vc *ClusterActuator) fetchKubeConfig(cluster *clusterv1.Cluster, masters []*clusterv1.Machine) (string, error) {
func (ca *ClusterActuator) fetchKubeConfig(cluster *clusterv1.Cluster, masters []*clusterv1.Machine) (string, error) {
var kubeconfig string
glog.Infof("attempting to fetch kubeconfig")
secret, err := vc.k8sClient.Core().Secrets(cluster.Namespace).Get(fmt.Sprintf(constants.KubeConfigSecretName, cluster.UID), metav1.GetOptions{})
secret, err := ca.k8sClient.Core().Secrets(cluster.Namespace).Get(fmt.Sprintf(constants.KubeConfigSecretName, cluster.UID), metav1.GetOptions{})
if err != nil {
glog.Info("could not pull secrets for kubeconfig")
// TODO: Check for the proper err type for *not present* case. rather than all other cases
Expand All @@ -115,7 +115,7 @@ func (vc *ClusterActuator) fetchKubeConfig(cluster *clusterv1.Cluster, masters [
},
StringData: configmap,
}
secret, err = vc.k8sClient.Core().Secrets(cluster.Namespace).Create(secret)
secret, err = ca.k8sClient.Core().Secrets(cluster.Namespace).Create(secret)
if err != nil {
glog.Warningf("Could not create the secret for the saving kubeconfig: err [%s]", err.Error())
}
Expand All @@ -126,8 +126,8 @@ func (vc *ClusterActuator) fetchKubeConfig(cluster *clusterv1.Cluster, masters [
return kubeconfig, nil
}

func (vc *ClusterActuator) getClusterAPIStatus(cluster *clusterv1.Cluster) (vsphereconfig.APIStatus, error) {
masters, err := vsphereutils.GetMasterForCluster(cluster, vc.lister)
func (ca *ClusterActuator) getClusterAPIStatus(cluster *clusterv1.Cluster) (vsphereconfig.APIStatus, error) {
masters, err := vsphereutils.GetMasterForCluster(cluster, ca.lister)
if err != nil {
glog.Infof("Error retrieving master nodes for the cluster: %s", err)
return vsphereconfig.ApiNotReady, err
Expand All @@ -136,7 +136,7 @@ func (vc *ClusterActuator) getClusterAPIStatus(cluster *clusterv1.Cluster) (vsph
glog.Infof("No masters for the cluster [%s] present", cluster.Name)
return vsphereconfig.ApiNotReady, nil
}
kubeconfig, err := vc.fetchKubeConfig(cluster, masters)
kubeconfig, err := ca.fetchKubeConfig(cluster, masters)
if err != nil {
return vsphereconfig.ApiNotReady, err
}
Expand All @@ -162,7 +162,7 @@ func (vc *ClusterActuator) getClusterAPIStatus(cluster *clusterv1.Cluster) (vsph
return vsphereconfig.ApiReady, nil
}

func (vc *ClusterActuator) updateClusterAPIStatus(cluster *clusterv1.Cluster, newStatus vsphereconfig.APIStatus) error {
func (ca *ClusterActuator) updateClusterAPIStatus(cluster *clusterv1.Cluster, newStatus vsphereconfig.APIStatus) error {
oldProviderStatus, err := vsphereutils.GetClusterProviderStatus(cluster)
if err != nil {
return err
Expand All @@ -181,15 +181,15 @@ func (vc *ClusterActuator) updateClusterAPIStatus(cluster *clusterv1.Cluster, ne
out, err := json.Marshal(newProviderStatus)
ncluster := cluster.DeepCopy()
ncluster.Status.ProviderStatus = &runtime.RawExtension{Raw: out}
_, err = vc.clusterV1alpha1.Clusters(ncluster.Namespace).UpdateStatus(ncluster)
_, err = ca.clusterV1alpha1.Clusters(ncluster.Namespace).UpdateStatus(ncluster)
if err != nil {
glog.Infof("Error in updating the cluster api status from [%s] to [%s]: %s", oldProviderStatus.APIStatus, newStatus, err)
return err
}
return nil
}

func (vc *ClusterActuator) provisionLoadBalancer(cluster *clusterv1.Cluster) error {
func (ca *ClusterActuator) provisionLoadBalancer(cluster *clusterv1.Cluster) error {
// TODO(ssurana):
// 1. implement the lb provisioning
// 2. update the lb public endpoint to the cluster endpoint
Expand All @@ -198,9 +198,9 @@ func (vc *ClusterActuator) provisionLoadBalancer(cluster *clusterv1.Cluster) err

// ensureLoadBalancerMembers would be responsible for keeping the master API endpoints
// synced with the lb members at all times.
func (vc *ClusterActuator) ensureLoadBalancerMembers(cluster *clusterv1.Cluster) error {
func (ca *ClusterActuator) ensureLoadBalancerMembers(cluster *clusterv1.Cluster) error {
// This is the temporary implementation until we do the proper LB implementation
err := vc.setMasterNodeIPAsEndpoint(cluster)
err := ca.setMasterNodeIPAsEndpoint(cluster)
if err != nil {
glog.Infof("Error registering master node's IP as API Endpoint for the cluster: %s", err)
return err
Expand All @@ -210,10 +210,10 @@ func (vc *ClusterActuator) ensureLoadBalancerMembers(cluster *clusterv1.Cluster)

// TODO(ssurana): Remove this method once we have the proper lb implementation
// Temporary implementation: Simply use the first master IP that you can find
func (vc *ClusterActuator) setMasterNodeIPAsEndpoint(cluster *clusterv1.Cluster) error {
func (ca *ClusterActuator) setMasterNodeIPAsEndpoint(cluster *clusterv1.Cluster) error {
ncluster := cluster.DeepCopy()
if len(ncluster.Status.APIEndpoints) == 0 {
masters, err := vsphereutils.GetMasterForCluster(ncluster, vc.lister)
masters, err := vsphereutils.GetMasterForCluster(ncluster, ca.lister)
if err != nil {
glog.Infof("Error retrieving master nodes for the cluster: %s", err)
return err
Expand All @@ -231,21 +231,21 @@ func (vc *ClusterActuator) setMasterNodeIPAsEndpoint(cluster *clusterv1.Cluster)
Host: ip,
Port: constants.ApiServerPort,
}}
_, err = vc.clusterV1alpha1.Clusters(ncluster.Namespace).UpdateStatus(ncluster)
_, err = ca.clusterV1alpha1.Clusters(ncluster.Namespace).UpdateStatus(ncluster)
if err != nil {
vc.eventRecorder.Eventf(ncluster, corev1.EventTypeWarning, "Failed Update", "Error in updating API Endpoint: %s", err)
ca.eventRecorder.Eventf(ncluster, corev1.EventTypeWarning, "Failed Update", "Error in updating API Endpoint: %s", err)
glog.Infof("Error in updating the status: %s", err)
return err
}
vc.eventRecorder.Eventf(ncluster, corev1.EventTypeNormal, "Updated", "Updated API Endpoint to %v", ip)
ca.eventRecorder.Eventf(ncluster, corev1.EventTypeNormal, "Updated", "Updated API Endpoint to %v", ip)
}
}
return nil
}

// Delete will delete any cluster level resources for the cluster.
func (vc *ClusterActuator) Delete(cluster *clusterv1.Cluster) error {
vc.eventRecorder.Eventf(cluster, corev1.EventTypeNormal, "Deleted", "Deleting cluster %s", cluster.Name)
func (ca *ClusterActuator) Delete(cluster *clusterv1.Cluster) error {
ca.eventRecorder.Eventf(cluster, corev1.EventTypeNormal, "Deleted", "Deleting cluster %s", cluster.Name)
glog.Infof("Attempting to cleaning up resources of cluster %s", cluster.ObjectMeta.Name)
return nil
}
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions cloud/vsphere/deployer.go → pkg/cloud/vsphere/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package vsphere

import (
vsphereutils "sigs.k8s.io/cluster-api-provider-vsphere/cloud/vsphere/utils"
vsphereutils "sigs.k8s.io/cluster-api-provider-vsphere/pkg/cloud/vsphere/utils"
clustercommon "sigs.k8s.io/cluster-api/pkg/apis/cluster/common"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
)
Expand All @@ -37,7 +37,7 @@ func NewDeploymentClient() *DeploymentClient {
return &DeploymentClient{}
}

func (*DeploymentClient) GetIP(cluster *clusterv1.Cluster, machine *clusterv1.Machine) (string, error) {
func (d *DeploymentClient) GetIP(cluster *clusterv1.Cluster, machine *clusterv1.Machine) (string, error) {
return vsphereutils.GetIP(cluster, machine)
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/cluster-api-provider-vsphere/cloud/vsphere/provisioner/govmomi"
"sigs.k8s.io/cluster-api-provider-vsphere/cloud/vsphere/provisioner/terraform"
vsphereconfigv1 "sigs.k8s.io/cluster-api-provider-vsphere/cloud/vsphere/vsphereproviderconfig/v1alpha1"
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/cloud/vsphere/provisioner/govmomi"
"sigs.k8s.io/cluster-api-provider-vsphere/pkg/cloud/vsphere/provisioner/terraform"
vsphereconfigv1 "sigs.k8s.io/cluster-api-provider-vsphere/pkg/cloud/vsphere/vsphereproviderconfig/v1alpha1"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
clusterv1alpha1 "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/typed/cluster/v1alpha1"
v1alpha1 "sigs.k8s.io/cluster-api/pkg/client/informers_generated/externalversions/cluster/v1alpha1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"
"text/template"

vsphereutils "sigs.k8s.io/cluster-api-provider-vsphere/cloud/vsphere/utils"
vsphereutils "sigs.k8s.io/cluster-api-provider-vsphere/pkg/cloud/vsphere/utils"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
)

Expand Down
Loading

0 comments on commit 10c76a3

Please sign in to comment.