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

Commit

Permalink
Merge pull request #21 from neolit123/hack-boilerplate
Browse files Browse the repository at this point in the history
hack: include scripts for golint, gofmt, spelling, shellcheck, etc.
  • Loading branch information
k8s-ci-robot authored Jun 25, 2019
2 parents df91e19 + 73d0491 commit b2324ba
Show file tree
Hide file tree
Showing 29 changed files with 928 additions and 14 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
2 changes: 1 addition & 1 deletion OWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ approvers:

reviewers:
- cluster-api-maintainers
- cluster-api-provider-docker-maintainers
- cluster-api-provider-docker-maintainers
2 changes: 1 addition & 1 deletion SECURITY_CONTACTS
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
detiber
justinsb
luxas
timothysc
timothysc
8 changes: 6 additions & 2 deletions actuators/actuators.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"fmt"
"io/ioutil"

"sigs.k8s.io/cluster-api-provider-docker/kind/actions"
"github.com/pkg/errors"
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"
"sigs.k8s.io/kind/pkg/cluster/constants"
"sigs.k8s.io/kind/pkg/cluster/nodes"
Expand All @@ -39,12 +39,15 @@ func getRole(machine *clusterv1.Machine) string {
return setValue
}

// Cluster defines a cluster actuator object
type Cluster struct{}

// NewClusterActuator returns a new cluster actuator object
func NewClusterActuator() *Cluster {
return &Cluster{}
}

// Reconcile setups an external load balancer for the cluster if needed
func (c *Cluster) Reconcile(cluster *clusterv1.Cluster) error {
elb, err := getExternalLoadBalancerNode(cluster.Name)
if err != nil {
Expand Down Expand Up @@ -72,11 +75,12 @@ func getExternalLoadBalancerNode(clusterName string) (*nodes.Node, error) {
return nil, nil
}
if len(elb) > 1 {
return nil, errors.New("Too many external load balancers.")
return nil, errors.New("too many external load balancers")
}
return &elb[0], nil
}

// Delete can be used to delete a cluster
func (c *Cluster) Delete(cluster *clusterv1.Cluster) error {
fmt.Println("Cluster delete is not implemented.")
return nil
Expand Down
8 changes: 7 additions & 1 deletion actuators/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,22 @@ const (
clusterAPIControlPlaneSetLabel = "controlplane"
)

// Machine defines a machine actuator type
type Machine struct {
Core corev1.CoreV1Interface
ClusterAPI v1alpha1.ClusterV1alpha1Interface
}

// NewMachineActuator returns a new machine actuator object
func NewMachineActuator(clusterapi v1alpha1.ClusterV1alpha1Interface, core corev1.CoreV1Interface) *Machine {
return &Machine{
Core: core,
ClusterAPI: clusterapi,
}
}

// Have to print all the errors because cluster-api swallows them
// 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()
fmt.Printf("Creating a machine for cluster %q\n", c.Name)
Expand Down Expand Up @@ -175,11 +178,13 @@ func (m *Machine) Delete(ctx context.Context, cluster *clusterv1.Cluster, machin
return nil
}

// Update updates a machine
func (m *Machine) Update(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine) error {
fmt.Println("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) {
if machine.Spec.ProviderID != nil {
return true, nil
Expand Down Expand Up @@ -236,6 +241,7 @@ func providerID(name string) string {
return fmt.Sprintf("docker://%s", name)
}

// CAPIroleToKindRole converts a CAPI role to kind role
// TODO there is a better way to do this.
func CAPIroleToKindRole(CAPIRole string) string {
if CAPIRole == clusterAPIControlPlaneSetLabel {
Expand Down
2 changes: 1 addition & 1 deletion code-of-conduct.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Kubernetes Community Code of Conduct

Please refer to our [Kubernetes Community Code of Conduct](https://git.k8s.io/community/code-of-conduct.md)
Please refer to our [Kubernetes Community Code of Conduct](https://git.k8s.io/community/code-of-conduct.md)
6 changes: 6 additions & 0 deletions execer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Client struct {
ExtraEnv []string
}

// NewClient returns a new client object
func NewClient(command string) *Client {
return &Client{
Stdout: os.Stdout,
Expand All @@ -44,6 +45,9 @@ func NewClient(command string) *Client {
}
}

// PipeToCommand pipes a standard input stream to a client command, starts the command and waits
// until the client command has finished writing its standard output and standard error to the respective
// client buffers.
func (c *Client) PipeToCommand(stdin io.Reader, args ...string) error {
cmd := exec.Command(c.Command, args...)
cmd.Env = append(os.Environ(), c.ExtraEnv...)
Expand Down Expand Up @@ -83,6 +87,7 @@ func (c *Client) PipeToCommand(stdin io.Reader, args ...string) error {
return nil
}

// RunCommandReturnOutput runs a client command and returns its output
func (c *Client) RunCommandReturnOutput(args ...string) (string, error) {
cmd := exec.Command(c.Command, args...)
cmd.Env = append(os.Environ(), c.ExtraEnv...)
Expand Down Expand Up @@ -126,6 +131,7 @@ func (c *Client) RunCommandReturnOutput(args ...string) (string, error) {

}

// RunCommand runs a client command
func (c *Client) RunCommand(args ...string) error {
cmd := exec.Command(c.Command, args...)
cmd.Env = append(os.Environ(), c.ExtraEnv...)
Expand Down
25 changes: 25 additions & 0 deletions hack/update-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

# shellcheck source=/dev/null
source "$(dirname "$0")/utils.sh"
REPO_PATH=$(get_root_path)

"${REPO_PATH}"/hack/update-deps.sh
"${REPO_PATH}"/hack/update-gofmt.sh
27 changes: 27 additions & 0 deletions hack/update-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


set -o nounset
set -o errexit
set -o pipefail

# shellcheck source=/dev/null
source "$(dirname "$0")/utils.sh"
# cd to the root path
cd_root_path

export GO111MODULE="on"
go mod tidy
27 changes: 27 additions & 0 deletions hack/update-gofmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# script to run gofmt over our code (not vendor)
set -o errexit
set -o nounset
set -o pipefail

# shellcheck source=/dev/null
source "$(dirname "$0")/utils.sh"
# cd to the root path
cd_root_path

# update go fmt
go fmt ./...
24 changes: 24 additions & 0 deletions hack/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# get_root_path returns the root path of the project source tree
get_root_path() {
echo "$(git rev-parse --show-toplevel)"
}

# cd_root_path cds to the root path of the project source tree
cd_root_path() {
cd "$(get_root_path)" || exit
}
94 changes: 94 additions & 0 deletions hack/verify-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

# shellcheck source=/dev/null
source "$(dirname "$0")/utils.sh"

# set REPO_PATH
REPO_PATH=$(get_root_path)
cd "${REPO_PATH}"

# exit code, if a script fails we'll set this to 1
res=0

# run all verify scripts, optionally skipping any of them

if [[ "${VERIFY_WHITESPACE:-true}" == "true" ]]; then
echo "[*] Verifying whitespace..."
hack/verify-whitespace.sh || res=1
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_SPELLING:-true}" == "true" ]]; then
echo "[*] Verifying spelling..."
hack/verify-spelling.sh || res=1
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_BOILERPLATE:-true}" == "true" ]]; then
echo "[*] Verifying boilerplate..."
hack/verify-boilerplate.sh || res=1
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_GOFMT:-true}" == "true" ]]; then
echo "[*] Verifying gofmt..."
hack/verify-gofmt.sh || res=1
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_GOLINT:-true}" == "true" ]]; then
echo "[*] Verifying golint..."
hack/verify-golint.sh || res=1
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_GOVET:-true}" == "true" ]]; then
echo "[*] Verifying govet..."
hack/verify-govet.sh || res=1
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_DEPS:-true}" == "true" ]]; then
echo "[*] Verifying deps..."
hack/verify-deps.sh || res=1
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_GOTEST:-true}" == "true" ]]; then
echo "[*] Verifying gotest..."
hack/verify-gotest.sh || res=1
cd "${REPO_PATH}"
fi

if [[ "${VERIFY_BUILD:-true}" == "true" ]]; then
echo "[*] Verifying build..."
hack/verify-build.sh || res=1
cd "${REPO_PATH}"
fi

# exit based on verify scripts
if [[ "${res}" = 0 ]]; then
echo ""
echo "All verify checks passed, congrats!"
else
echo ""
echo "One or more verify checks failed! See output above..."
fi
exit "${res}"
Loading

0 comments on commit b2324ba

Please sign in to comment.