From 8e95bc26c9571a8609038b97fbb09ac46268dc2d Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Thu, 13 Sep 2018 13:47:20 +0200 Subject: [PATCH] Fix go lint complaints --- Makefile | 5 ++++- cloud/aws/actuators/machine/actuator.go | 10 +++++----- cloud/aws/actuators/machine/utils.go | 12 ++++++------ cloud/aws/client/client.go | 5 ++++- cloud/aws/controllers/cluster/controller.go | 2 ++ .../controllers/cluster/options/options.go | 2 ++ cloud/aws/controllers/machine/controller.go | 2 ++ .../controllers/machine/options/options.go | 2 ++ cloud/aws/providerconfig/register.go | 8 +++++++- cloud/aws/providerconfig/types.go | 2 ++ cloud/aws/providerconfig/v1alpha1/register.go | 19 ++++++++++++++++--- cloud/aws/providerconfig/v1alpha1/types.go | 1 + cmd/aws-actuator/main.go | 8 ++++---- test/utils/utils.go | 1 + 14 files changed, 58 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index a6ee445ec7..2ffc72d453 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ push: $(MAKE) -C cmd/cluster-controller push $(MAKE) -C cmd/machine-controller push -check: fmt vet +check: fmt vet lint test: go test -race -cover ./cmd/... ./cloud/... @@ -60,3 +60,6 @@ fmt: vet: hack/go-vet.sh ./... + +lint: + hack/go-lint.sh $$(go list -f '{{ .ImportPath }}' ./...) diff --git a/cloud/aws/actuators/machine/actuator.go b/cloud/aws/actuators/machine/actuator.go index 5e7b36d0d4..b91e65d8d2 100644 --- a/cloud/aws/actuators/machine/actuator.go +++ b/cloud/aws/actuators/machine/actuator.go @@ -179,7 +179,7 @@ func getSubnetIDs(subnet providerconfigv1.AWSResourceReference, client awsclient func (a *Actuator) CreateMachine(cluster *clusterv1.Cluster, machine *clusterv1.Machine) (*ec2.Instance, error) { mLog := clustoplog.WithMachine(a.logger, machine) - machineProviderConfig, err := MachineProviderConfigFromClusterAPIMachineSpec(&machine.Spec) + machineProviderConfig, err := ProviderConfigFromClusterAPIMachineSpec(&machine.Spec) if err != nil { mLog.Errorf("error decoding MachineProviderConfig: %v", err) return nil, err @@ -196,7 +196,7 @@ func (a *Actuator) CreateMachine(cluster *clusterv1.Cluster, machine *clusterv1. } // We explicitly do NOT want to remove stopped masters. - if !MachineIsMaster(machine) { + if !IsMaster(machine) { // Prevent having a lot of stopped nodes sitting around. err = a.removeStoppedMachine(machine, client, mLog) if err != nil { @@ -355,7 +355,7 @@ func (a *Actuator) Delete(cluster *clusterv1.Cluster, machine *clusterv1.Machine func (a *Actuator) DeleteMachine(cluster *clusterv1.Cluster, machine *clusterv1.Machine) error { mLog := clustoplog.WithMachine(a.logger, machine) - machineProviderConfig, err := MachineProviderConfigFromClusterAPIMachineSpec(&machine.Spec) + machineProviderConfig, err := ProviderConfigFromClusterAPIMachineSpec(&machine.Spec) if err != nil { mLog.Errorf("error decoding MachineProviderConfig: %v", err) return err @@ -392,7 +392,7 @@ func (a *Actuator) Update(cluster *clusterv1.Cluster, machine *clusterv1.Machine mLog := clustoplog.WithMachine(a.logger, machine) mLog.Debugf("updating machine") - machineProviderConfig, err := MachineProviderConfigFromClusterAPIMachineSpec(&machine.Spec) + machineProviderConfig, err := ProviderConfigFromClusterAPIMachineSpec(&machine.Spec) if err != nil { mLog.Errorf("error decoding MachineProviderConfig: %v", err) return err @@ -454,7 +454,7 @@ func (a *Actuator) Exists(cluster *clusterv1.Cluster, machine *clusterv1.Machine mLog := clustoplog.WithMachine(a.logger, machine) mLog.Debugf("checking if machine exists") - machineProviderConfig, err := MachineProviderConfigFromClusterAPIMachineSpec(&machine.Spec) + machineProviderConfig, err := ProviderConfigFromClusterAPIMachineSpec(&machine.Spec) if err != nil { mLog.Errorf("error decoding MachineProviderConfig: %v", err) return false, err diff --git a/cloud/aws/actuators/machine/utils.go b/cloud/aws/actuators/machine/utils.go index 1531a64522..a79601bac1 100644 --- a/cloud/aws/actuators/machine/utils.go +++ b/cloud/aws/actuators/machine/utils.go @@ -183,9 +183,9 @@ func TerminateInstances(client awsclient.Client, instances []*ec2.Instance, mLog return nil } -// MachineProviderFromClusterAPIMachineSpec gets the machine provider config MachineSetSpec from the +// ProviderConfigFromClusterAPIMachineSpec gets the machine provider config MachineSetSpec from the // specified cluster-api MachineSpec. -func MachineProviderConfigFromClusterAPIMachineSpec(ms *clusterv1.MachineSpec) (*providerconfigv1.AWSMachineProviderConfig, error) { +func ProviderConfigFromClusterAPIMachineSpec(ms *clusterv1.MachineSpec) (*providerconfigv1.AWSMachineProviderConfig, error) { if ms.ProviderConfig.Value == nil { return nil, fmt.Errorf("no Value in ProviderConfig") } @@ -238,16 +238,16 @@ func EncodeAWSMachineProviderStatus(awsStatus *providerconfigv1.AWSMachineProvid }, nil } -// MachineIsMaster returns true if the machine is part of a cluster's control plane -func MachineIsMaster(machine *clusterv1.Machine) bool { +// IsMaster returns true if the machine is part of a cluster's control plane +func IsMaster(machine *clusterv1.Machine) bool { if machineType, exists := machine.ObjectMeta.Labels[providerconfigv1.MachineTypeLabel]; exists && machineType == "master" { return true } return false } -// MachineIsInfra returns true if the machine is part of a cluster's infra plane -func MachineIsInfra(machine *clusterv1.Machine) bool { +// IsInfra returns true if the machine is part of a cluster's infra plane +func IsInfra(machine *clusterv1.Machine) bool { if machineRole, exists := machine.ObjectMeta.Labels[providerconfigv1.MachineRoleLabel]; exists && machineRole == "infra" { return true } diff --git a/cloud/aws/client/client.go b/cloud/aws/client/client.go index eccfe24056..38e8c4348d 100644 --- a/cloud/aws/client/client.go +++ b/cloud/aws/client/client.go @@ -34,10 +34,13 @@ import ( //go:generate mockgen -source=./client.go -destination=./mock/client_generated.go -package=mock const ( - AwsCredsSecretIDKey = "awsAccessKeyId" + // AwsCredsSecretIDKey is secret key containing AWS KeyId + AwsCredsSecretIDKey = "awsAccessKeyId" + // AwsCredsSecretAccessKey is secret key containing AWS Secret Key AwsCredsSecretAccessKey = "awsSecretAccessKey" ) +// AwsClientBuilderFuncType is function type for building aws client type AwsClientBuilderFuncType func(kubeClient kubernetes.Interface, secretName, namespace, region string) (Client, error) // Client is a wrapper object for actual AWS SDK clients to allow for easier testing. diff --git a/cloud/aws/controllers/cluster/controller.go b/cloud/aws/controllers/cluster/controller.go index ee2b2cee8f..49d2cf1ca5 100644 --- a/cloud/aws/controllers/cluster/controller.go +++ b/cloud/aws/controllers/cluster/controller.go @@ -45,6 +45,7 @@ const ( controllerName = "aws-cluster-controller" ) +// Start starts the cluster controller func Start(server *options.Server, shutdown <-chan struct{}) { config, err := controller.GetConfig(server.CommonConfig.Kubeconfig) if err != nil { @@ -71,6 +72,7 @@ func Start(server *options.Server, shutdown <-chan struct{}) { select {} } +// Run runs the cluster controller func Run(server *options.Server) error { kubeConfig, err := controller.GetConfig(server.CommonConfig.Kubeconfig) if err != nil { diff --git a/cloud/aws/controllers/cluster/options/options.go b/cloud/aws/controllers/cluster/options/options.go index fe56660429..34cc57a3e8 100644 --- a/cloud/aws/controllers/cluster/options/options.go +++ b/cloud/aws/controllers/cluster/options/options.go @@ -20,10 +20,12 @@ import ( "sigs.k8s.io/cluster-api/pkg/controller/config" ) +// Server type with server configuration type Server struct { CommonConfig *config.Configuration } +// NewServer builds a service configuration func NewServer() *Server { s := Server{ CommonConfig: &config.ControllerConfig, diff --git a/cloud/aws/controllers/machine/controller.go b/cloud/aws/controllers/machine/controller.go index d6d5cf92e7..b504061e79 100644 --- a/cloud/aws/controllers/machine/controller.go +++ b/cloud/aws/controllers/machine/controller.go @@ -48,6 +48,7 @@ const ( controllerName = "aws-machine-controller" ) +// Start starts the server func Start(server *options.Server, shutdown <-chan struct{}) { config, err := controller.GetConfig(server.CommonConfig.Kubeconfig) if err != nil { @@ -82,6 +83,7 @@ func Start(server *options.Server, shutdown <-chan struct{}) { select {} } +// Run runs the server func Run(server *options.Server) error { kubeConfig, err := controller.GetConfig(server.CommonConfig.Kubeconfig) if err != nil { diff --git a/cloud/aws/controllers/machine/options/options.go b/cloud/aws/controllers/machine/options/options.go index fe56660429..e7b7d19cfe 100644 --- a/cloud/aws/controllers/machine/options/options.go +++ b/cloud/aws/controllers/machine/options/options.go @@ -20,10 +20,12 @@ import ( "sigs.k8s.io/cluster-api/pkg/controller/config" ) +// Server type with server configuration type Server struct { CommonConfig *config.Configuration } +// NewServer builds a server configuration func NewServer() *Server { s := Server{ CommonConfig: &config.ControllerConfig, diff --git a/cloud/aws/providerconfig/register.go b/cloud/aws/providerconfig/register.go index 9ffc67e34a..3227420d1a 100644 --- a/cloud/aws/providerconfig/register.go +++ b/cloud/aws/providerconfig/register.go @@ -19,7 +19,9 @@ import ( ) var ( - SchemeBuilder runtime.SchemeBuilder + // SchemeBuilder with scheme builder + SchemeBuilder runtime.SchemeBuilder + // AddToScheme is method for adding objects to the scheme AddToScheme = SchemeBuilder.AddToScheme localSchemeBuilder = &SchemeBuilder ) @@ -28,14 +30,18 @@ func init() { localSchemeBuilder.Register(addKnownTypes) } +// GroupName is group name of the cluster kinds const GroupName = "aws.cluster.k8s.io" +// SchemeGroupVersion is scheme group version of the cluster kinds var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} +// Kind returns group kind for a given kind/object func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } +// Resource returns group resource for a given resource func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/cloud/aws/providerconfig/types.go b/cloud/aws/providerconfig/types.go index 16b56cc324..c51b253d40 100644 --- a/cloud/aws/providerconfig/types.go +++ b/cloud/aws/providerconfig/types.go @@ -114,6 +114,7 @@ type TagSpecification struct { Value string } +// AWSClusterProviderConfig is aws speific configuration // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object type AWSClusterProviderConfig struct { metav1.TypeMeta @@ -166,6 +167,7 @@ type AWSMachineProviderCondition struct { Message string } +// AWSClusterProviderStatus is AWS specific status // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object type AWSClusterProviderStatus struct { metav1.TypeMeta diff --git a/cloud/aws/providerconfig/v1alpha1/register.go b/cloud/aws/providerconfig/v1alpha1/register.go index 2462e584a1..164d141dc0 100644 --- a/cloud/aws/providerconfig/v1alpha1/register.go +++ b/cloud/aws/providerconfig/v1alpha1/register.go @@ -25,26 +25,33 @@ import ( "sigs.k8s.io/cluster-api-provider-aws/cloud/aws/providerconfig" ) +// AWSProviderConfigCodec carries AWS provider configuration encoder/decoder // +k8s:deepcopy-gen=false type AWSProviderConfigCodec struct { encoder runtime.Encoder decoder runtime.Decoder } +// GroupName is group name of the cluster kinds const GroupName = "aws.cluster.k8s.io" +// SchemeGroupVersion is scheme group version of the cluster kinds var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"} var ( + // SchemeBuilder with scheme builder SchemeBuilder runtime.SchemeBuilder localSchemeBuilder = &SchemeBuilder - AddToScheme = localSchemeBuilder.AddToScheme + // AddToScheme is method for adding objects to the scheme + AddToScheme = localSchemeBuilder.AddToScheme ) var ( + // Scheme with new scheme + Scheme, _ = NewScheme() // Codecs for creating a server config - Scheme, _ = NewScheme() - Codecs = serializer.NewCodecFactory(Scheme) + Codecs = serializer.NewCodecFactory(Scheme) + // Encoder for encoding cluster objects Encoder, _ = newEncoder(&Codecs) ) @@ -68,6 +75,7 @@ func addKnownTypes(scheme *runtime.Scheme) error { return nil } +// NewScheme builds new scheme func NewScheme() (*runtime.Scheme, error) { scheme := runtime.NewScheme() if err := AddToScheme(scheme); err != nil { @@ -80,6 +88,7 @@ func NewScheme() (*runtime.Scheme, error) { return scheme, nil } +// NewCodec builds new coder and encoder func NewCodec() (*AWSProviderConfigCodec, error) { scheme, err := NewScheme() if err != nil { @@ -97,6 +106,7 @@ func NewCodec() (*AWSProviderConfigCodec, error) { return &codec, nil } +// DecodeFromProviderConfig decodes provider config into accessible object func (codec *AWSProviderConfigCodec) DecodeFromProviderConfig(providerConfig clusterv1.ProviderConfig, out runtime.Object) error { if providerConfig.Value != nil { _, _, err := codec.decoder.Decode(providerConfig.Value.Raw, nil, out) @@ -107,6 +117,7 @@ func (codec *AWSProviderConfigCodec) DecodeFromProviderConfig(providerConfig clu return nil } +// EncodeToProviderConfig encodes provider config into raw bytes func (codec *AWSProviderConfigCodec) EncodeToProviderConfig(in runtime.Object) (*clusterv1.ProviderConfig, error) { var buf bytes.Buffer if err := codec.encoder.Encode(in, &buf); err != nil { @@ -117,6 +128,7 @@ func (codec *AWSProviderConfigCodec) EncodeToProviderConfig(in runtime.Object) ( }, nil } +// EncodeProviderStatus decodes provider status into accessible object func (codec *AWSProviderConfigCodec) EncodeProviderStatus(in runtime.Object) (*runtime.RawExtension, error) { var buf bytes.Buffer if err := codec.encoder.Encode(in, &buf); err != nil { @@ -126,6 +138,7 @@ func (codec *AWSProviderConfigCodec) EncodeProviderStatus(in runtime.Object) (*r return &runtime.RawExtension{Raw: buf.Bytes()}, nil } +// DecodeProviderStatus encodes status into raw bytes func (codec *AWSProviderConfigCodec) DecodeProviderStatus(providerStatus *runtime.RawExtension, out runtime.Object) error { if providerStatus != nil { _, _, err := codec.decoder.Decode(providerStatus.Raw, nil, out) diff --git a/cloud/aws/providerconfig/v1alpha1/types.go b/cloud/aws/providerconfig/v1alpha1/types.go index c495d65284..0a7bda9827 100644 --- a/cloud/aws/providerconfig/v1alpha1/types.go +++ b/cloud/aws/providerconfig/v1alpha1/types.go @@ -115,6 +115,7 @@ type TagSpecification struct { Value string `json:"value"` } +// AWSClusterProviderStatus is AWS specific status // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object type AWSClusterProviderStatus struct { metav1.TypeMeta `json:",inline"` diff --git a/cmd/aws-actuator/main.go b/cmd/aws-actuator/main.go index 8348fa3b9d..afd80e05ac 100644 --- a/cmd/aws-actuator/main.go +++ b/cmd/aws-actuator/main.go @@ -222,12 +222,12 @@ bash /root/user-data.sh > /root/user-data.logs ` type userDataParams struct { - MasterIP string + masterIP string } -func generateWorkerUserData(masterIp string, workerUserDataSecret *apiv1.Secret) (*apiv1.Secret, error) { +func generateWorkerUserData(masterIP string, workerUserDataSecret *apiv1.Secret) (*apiv1.Secret, error) { params := userDataParams{ - MasterIP: masterIp, + masterIP: masterIP, } t, err := template.New("workeruserdata").Parse(workerUserDataBlob) if err != nil { @@ -312,7 +312,7 @@ func bootstrapCommand() *cobra.Command { log.Infof("Generating worker user data for master listening at %v", *result.PrivateIpAddress) workerUserDataSecret, err = generateWorkerUserData(*result.PrivateIpAddress, workerUserDataSecret) if err != nil { - return fmt.Errorf("Unable to generate worker user data: %v\n", err) + return fmt.Errorf("unable to generate worker user data: %v", err) } log.Infof("Creating worker machine") diff --git a/test/utils/utils.go b/test/utils/utils.go index 69b9329bcd..ad08ed0a9d 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -8,6 +8,7 @@ import ( awsclient "sigs.k8s.io/cluster-api-provider-aws/cloud/aws/client" ) +// GenerateAwsCredentialsSecretFromEnv generates secret with AWS credentials func GenerateAwsCredentialsSecretFromEnv(secretName, namespace string) *apiv1.Secret { return &apiv1.Secret{ ObjectMeta: metav1.ObjectMeta{