Skip to content

Commit

Permalink
codeclimate fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xetys committed Apr 22, 2018
1 parent e6b8a4f commit 6efb4a1
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cmd/cluster_addon_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
package cmd

import (
"github.com/spf13/cobra"
"text/tabwriter"
"os"
"fmt"
"github.com/spf13/cobra"
"github.com/xetys/hetzner-kube/pkg/addons"
"github.com/xetys/hetzner-kube/pkg/clustermanager"
"github.com/xetys/hetzner-kube/pkg/hetzner"
"github.com/xetys/hetzner-kube/pkg/addons"
"os"
"strings"
"text/tabwriter"
)

// clusterAddonInstallCmd represents the clusterAddonInstall command
Expand Down
4 changes: 4 additions & 0 deletions docs/cluster-addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func (addon *NginxAddon) Name() string {
return "nginx"
}

func (addon *NginxAddon) Requires() []string {
return []string{}
}

func (addon *NginxAddon) Description() string {
return "a simple nginx deployment"
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/addons/addon_cert_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type CertmanagerAddon struct {
communicator clustermanager.NodeCommunicator
}

// NewCertmanagerAddon creates an addon installing cert-manager
func NewCertmanagerAddon(cluster clustermanager.ClusterProvider, communicator clustermanager.NodeCommunicator) ClusterAddon {
masterNode, err := cluster.GetMasterNode()
FatalOnError(err)
Expand All @@ -20,21 +21,27 @@ func init() {
addAddon(NewCertmanagerAddon)
}

//Name returns the addons name
func (addon *CertmanagerAddon) Name() string {
return "cert-manager"
}

//Requires returns a slice with the name of required addons
func (addon *CertmanagerAddon) Requires() []string {
return []string{"helm"}
}

//Description returns the addons description
func (addon *CertmanagerAddon) Description() string {
return "Auto-TLS provisioning & management"
}

//URL returns the URL of the addons underlying project
func (addon *CertmanagerAddon) URL() string {
return "https://github.com/jetstack/cert-manager"
}

//Install performs all steps to install the addon
func (addon *CertmanagerAddon) Install(args ...string) {
node := *addon.masterNode
_, err := addon.communicator.RunCmd(node, "helm install --name cert-manager --namespace ingress stable/cert-manager")
Expand Down
7 changes: 7 additions & 0 deletions pkg/addons/addon_docker_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type DockerregistryAddon struct {
communicator clustermanager.NodeCommunicator
}

// NewDockerregistryAddon creates an addon providing a private docker registry
func NewDockerregistryAddon(provider clustermanager.ClusterProvider, communicator clustermanager.NodeCommunicator) ClusterAddon {
masterNode, err := provider.GetMasterNode()
FatalOnError(err)
Expand All @@ -20,29 +21,35 @@ func init() {
addAddon(NewDockerregistryAddon)
}

//Name returns the addons name
func (addon *DockerregistryAddon) Name() string {
return "docker-registry"
}

//Requires returns a slice with the name of required addons
func (addon *DockerregistryAddon) Requires() []string {
return []string{"helm"}
}

//Description returns the addons description
func (addon *DockerregistryAddon) Description() string {
return "Private container registry"
}

//URL returns the URL of the addons underlying project
func (addon *DockerregistryAddon) URL() string {
return "https://github.com/kubernetes/charts/tree/master/stable/docker-registry"
}

//Install performs all steps to install the addon
func (addon *DockerregistryAddon) Install(args ...string) {
node := *addon.masterNode
_, err := addon.communicator.RunCmd(node, "helm install --set persistence.enabled=true stable/docker-registry")
FatalOnError(err)
log.Println("docker-registry installed")
}

//Uninstall performs all steps to remove the addon
func (addon DockerregistryAddon) Uninstall() {
node := *addon.masterNode
_, err := addon.communicator.RunCmd(node, "helm delete --purge docker-registry")
Expand Down
7 changes: 7 additions & 0 deletions pkg/addons/addon_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type HelmAddon struct {
communicator clustermanager.NodeCommunicator
}

//NewHelmAddon installs helm to the cluster
func NewHelmAddon(provider clustermanager.ClusterProvider, communicator clustermanager.NodeCommunicator) ClusterAddon {
masterNode, _ := provider.GetMasterNode()
return HelmAddon{masterNode: masterNode, communicator: communicator}
Expand All @@ -19,22 +20,27 @@ func init() {
addAddon(NewHelmAddon)
}

//Name returns the addons name
func (addon HelmAddon) Name() string {
return "helm"
}

//Requires returns a slice with the name of required addons
func (addon HelmAddon) Requires() []string {
return []string{}
}

//Description returns the addons description
func (addon HelmAddon) Description() string {
return "Kuberntes Package Manager"
}

//URL returns the URL of the addons underlying project
func (addon HelmAddon) URL() string {
return "https://helm.sh"
}

//Install performs all steps to install the addon
func (addon HelmAddon) Install(args ...string) {

node := *addon.masterNode
Expand Down Expand Up @@ -70,6 +76,7 @@ subjects:
fmt.Println("Helm installed")
}

//Uninstall performs all steps to remove the addon
func (addon HelmAddon) Uninstall() {
node := *addon.masterNode
_, err := addon.communicator.RunCmd(node, "helm reset --force")
Expand Down
7 changes: 7 additions & 0 deletions pkg/addons/addon_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type IngressAddon struct {
communicator clustermanager.NodeCommunicator
}

//NewIngressAddon creates an addon to install a nginx ingress controller
func NewIngressAddon(provider clustermanager.ClusterProvider, communicator clustermanager.NodeCommunicator) ClusterAddon {
masterNode, err := provider.GetMasterNode()
FatalOnError(err)
Expand All @@ -20,29 +21,35 @@ func init() {
addAddon(NewIngressAddon)
}

//Name returns the addons name
func (addon *IngressAddon) Name() string {
return "nginx ingress controller"
}

//Requires returns a slice with the name of required addons
func (addon *IngressAddon) Requires() []string {
return []string{"helm"}
}

//Description returns the addons description
func (addon *IngressAddon) Description() string {
return "an ingress based load balancer for K8S"
}

//URL returns the URL of the addons underlying project
func (addon *IngressAddon) URL() string {
return ""
}

//Install performs all steps to install the addon
func (addon *IngressAddon) Install(args ...string) {
node := *addon.masterNode
_, err := addon.communicator.RunCmd(node, "helm install --name ingress --namespace ingress --set rbac.create=true,controller.kind=DaemonSet,controller.service.type=ClusterIP,controller.hostNetwork=true stable/nginx-ingress")
FatalOnError(err)
log.Println("nginx ingress installed")
}

//Uninstall performs all steps to remove the addon
func (addon *IngressAddon) Uninstall() {
node := *addon.masterNode
_, err := addon.communicator.RunCmd(node, "helm delete --purge ingress")
Expand Down
7 changes: 7 additions & 0 deletions pkg/addons/addon_openebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type OpenEBSAddon struct {
communicator clustermanager.NodeCommunicator
}

//NewOpenEBSAddon creates an addon which installs OpenEBS
func NewOpenEBSAddon(provider clustermanager.ClusterProvider, communicator clustermanager.NodeCommunicator) ClusterAddon {
masterNode, _ := provider.GetMasterNode()
return &OpenEBSAddon{masterNode: masterNode, communicator: communicator}
Expand All @@ -19,22 +20,27 @@ func init() {
addAddon(NewOpenEBSAddon)
}

//Name returns the addons name
func (addon OpenEBSAddon) Name() string {
return "OpenEBS"
}

//Requires returns a slice with the name of required addons
func (addon OpenEBSAddon) Requires() []string {
return []string{}
}

//Description returns the addons description
func (addon OpenEBSAddon) Description() string {
return "Simple scalable block storage provider"
}

//URL returns the URL of the addons underlying project
func (addon OpenEBSAddon) URL() string {
return "https://openebs.io/"
}

//Install performs all steps to install the addon
func (addon OpenEBSAddon) Install(args ...string) {
node := *addon.masterNode

Expand All @@ -60,6 +66,7 @@ parameters:
fmt.Println("OpenEBS installed")
}

//Uninstall performs all steps to remove the addon
func (addon OpenEBSAddon) Uninstall() {
node := *addon.masterNode

Expand Down
7 changes: 7 additions & 0 deletions pkg/addons/addon_rook.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type RookAddon struct {
nodes []clustermanager.Node
}

//NewRookAddon creates an addon which install rook
func NewRookAddon(provider clustermanager.ClusterProvider, communicator clustermanager.NodeCommunicator) ClusterAddon {
masterNode, _ := provider.GetMasterNode()
return &RookAddon{masterNode: masterNode, communicator: communicator, nodes: provider.GetAllNodes()}
Expand All @@ -21,22 +22,27 @@ func init() {
addAddon(NewRookAddon)
}

//Name returns the addons name
func (addon RookAddon) Name() string {
return "rook"
}

//Requires returns a slice with the name of required addons
func (addon RookAddon) Requires() []string {
return []string{}
}

//Description returns the addons description
func (addon RookAddon) Description() string {
return "File, Block and Object Storage provider"
}

//URL returns the URL of the addons underlying project
func (addon RookAddon) URL() string {
return "https://rook.io"
}

//Install performs all steps to install the addon
func (addon RookAddon) Install(args ...string) {
node := *addon.masterNode

Expand Down Expand Up @@ -64,6 +70,7 @@ func (addon RookAddon) Install(args ...string) {
fmt.Println("Rook installed")
}

//Uninstall performs all steps to remove the addon
func (addon RookAddon) Uninstall() {
node := *addon.masterNode
addon.communicator.RunCmd(node, "kubectl delete -n rook pool replicapool")
Expand Down
4 changes: 4 additions & 0 deletions pkg/addons/cluster_addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type ClusterAddonService struct {
addons []ClusterAddon
}

//NewClusterAddonService creates an instance of the cluster addon service
func NewClusterAddonService(provider clustermanager.ClusterProvider, nodeComm clustermanager.NodeCommunicator) *ClusterAddonService {
clusterAddons := []ClusterAddon{}
for _, initializer := range addonInitializers {
Expand All @@ -33,6 +34,7 @@ func NewClusterAddonService(provider clustermanager.ClusterProvider, nodeComm cl
return &ClusterAddonService{provider: provider, nodeCommunicator: nodeComm, addons: clusterAddons}
}

//AddonExists return true, if an addon with the requested name exists
func (addonService *ClusterAddonService) AddonExists(addonName string) bool {
for _, addon := range addonService.addons {
if addon.Name() == addonName {
Expand All @@ -42,6 +44,7 @@ func (addonService *ClusterAddonService) AddonExists(addonName string) bool {
return false
}

//GetAddon returns the ClusterAddon instance given by name, or nil if not found
func (addonService *ClusterAddonService) GetAddon(addonName string) ClusterAddon {
for _, addon := range addonService.addons {
if addon.Name() == addonName {
Expand All @@ -52,6 +55,7 @@ func (addonService *ClusterAddonService) GetAddon(addonName string) ClusterAddon
return nil
}

//Addons returns a list of all addons
func (addonService *ClusterAddonService) Addons() []ClusterAddon {
return addonService.addons
}
2 changes: 1 addition & 1 deletion pkg/clustermanager/ssh_communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var _ NodeCommunicator = &SSHCommunicator{}

func NewSSHCommunicator(sshKeys []SSHKey) NodeCommunicator {
return &SSHCommunicator{
sshKeys: sshKeys,
sshKeys: sshKeys,
passPhrases: make(map[string][]byte),
}
}
Expand Down

0 comments on commit 6efb4a1

Please sign in to comment.