Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more lint errors from goreportcard #34

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ vet: ## Run go vet on the whole project.
go vet ./...

.PHONY: lint
lint: bin/golangci-lint generate-mocks ## Run linting for the project.
lint: bin/golangci-lint bin/golint generate-mocks ## Run linting for the project.
go fmt ./...
go vet ./...
golint ./...
golangci-lint run -v --timeout 360s ./...
@ # The below string of commands checks that ginkgo isn't present in the controllers.
@(grep ginkgo ${PROJECT_DIR}/controllers/cloudstack*_controller.go && \
Expand Down Expand Up @@ -141,6 +142,8 @@ bin/ginkgo: ## Install ginkgo to bin.
GOBIN=$(PROJECT_DIR)/bin go install github.com/onsi/ginkgo/ginkgo@v1.16.5
bin/mockgen:
GOBIN=$(PROJECT_DIR)/bin go install github.com/golang/mock/mockgen@v1.6.0
bin/golint:
GOBIN=$(PROJECT_DIR)/bin go install golang.org/x/lint/golint
bin/kustomize: ## Install kustomize to bin.
@mkdir -p bin
cd bin && curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
Expand Down
12 changes: 6 additions & 6 deletions api/v1beta1/cloudstackcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import (
)

const (
// The presence of a finalizer prevents CAPI from deleting the corresponding CAPI data.
// ClusterFinalizer prevents CAPI from deleting the corresponding CAPI data.
ClusterFinalizer = "cloudstackcluster.infrastructure.cluster.x-k8s.io"
defaultIdentityRefKind = "Secret"
)

// CloudStackIdentityReference is a reference to an infrastructure
// CloudStackIdentityReference is a reference to an infrastructure.
// provider identity to be used to provision cluster resources.
type CloudStackIdentityReference struct {
// Kind of the identity. Must be supported by the infrastructure provider
// Kind of the identity. Must be supported by the infrastructure provider.
// and may be either cluster or namespace-scoped.
// +kubebuilder:validation:MinLength=1
Kind string `json:"kind"`
Expand Down Expand Up @@ -63,7 +63,7 @@ type CloudStackClusterSpec struct {
IdentityRef *CloudStackIdentityReference `json:"identityRef,omitempty"`
}

// The status of the abstract CS k8s (not an actual Cloudstack Cluster) cluster.
// CloudStackClusterStatus is the status of the abstract CS k8s (not an actual Cloudstack Cluster) cluster.
type CloudStackClusterStatus struct {
// Reflects the readiness of the CS cluster.
Ready bool `json:"ready"`
Expand All @@ -90,7 +90,7 @@ type CloudStackClusterStatus struct {
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// CloudStackCluster is the Schema for the cloudstackclusters API
// CloudStackCluster is the Schema for the cloudstackclusters API.
type CloudStackCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -103,7 +103,7 @@ type CloudStackCluster struct {

//+kubebuilder:object:root=true

// CloudStackClusterList contains a list of CloudStackCluster
// CloudStackClusterList contains a list of CloudStackCluster.
type CloudStackClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
13 changes: 7 additions & 6 deletions api/v1beta1/cloudstackcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
// log is for logging in this package.
var cloudstackclusterlog = logf.Log.WithName("cloudstackcluster-resource")

// SetupWebhookWithManager creates a new webhook managed by passed manager.
func (r *CloudStackCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Expand All @@ -41,7 +42,7 @@ func (r *CloudStackCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {

var _ webhook.Defaulter = &CloudStackCluster{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (r *CloudStackCluster) Default() {
cloudstackclusterlog.Info("default", "name", r.Name)
// No defaulted values supported yet.
Expand All @@ -51,7 +52,7 @@ func (r *CloudStackCluster) Default() {

var _ webhook.Validator = &CloudStackCluster{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackCluster) ValidateCreate() error {
cloudstackclusterlog.Info("validate create", "name", r.Name)

Expand All @@ -66,14 +67,14 @@ func (r *CloudStackCluster) ValidateCreate() error {
errorList = append(errorList, field.Required(field.NewPath("spec", "account"), "specifying account requires additionally specifying domain"))
}

// Zone and Network are required fields
// Zone and Network are required fields.
errorList = webhookutil.EnsureFieldExists(r.Spec.Zone, "Zone", errorList)
errorList = webhookutil.EnsureFieldExists(r.Spec.Network, "Network", errorList)

return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackCluster) ValidateUpdate(old runtime.Object) error {
cloudstackclusterlog.Info("validate update", "name", r.Name)

Expand All @@ -93,7 +94,7 @@ func (r *CloudStackCluster) ValidateUpdate(old runtime.Object) error {
errorList = append(errorList, field.Forbidden(field.NewPath("spec", "identityRef", "kind"), "must be a Secret"))
}

// No spec fields may be changed
// No spec fields may be changed.
errorList = webhookutil.EnsureStringFieldsAreEqual(spec.Zone, oldSpec.Zone, "zone", errorList)
errorList = webhookutil.EnsureStringFieldsAreEqual(spec.Network, oldSpec.Network, "network", errorList)
if oldSpec.ControlPlaneEndpoint.Host != "" { // Need to allow one time endpoint setting via CAPC cluster controller.
Expand All @@ -110,7 +111,7 @@ func (r *CloudStackCluster) ValidateUpdate(old runtime.Object) error {
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackCluster) ValidateDelete() error {
cloudstackclusterlog.Info("validate delete", "name", r.Name)
// No deletion validations. Deletion webhook not enabled.
Expand Down
25 changes: 11 additions & 14 deletions api/v1beta1/cloudstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import (
)

const (
// The presence of a finalizer prevents CAPI from deleting the corresponding CAPI data.
// MachineFinalizer prevents CAPI from deleting the corresponding CAPI data.
MachineFinalizer = "cloudstackmachine.infrastructure.cluster.x-k8s.io"
)

// CloudStackMachineSpec defines the desired state of CloudStackMachine
// CloudStackMachineSpec defines the desired state of CloudStackMachine.
type CloudStackMachineSpec struct {
// Instance ID. Should only be useful to modify an existing instance.
InstanceID *string `json:"instanceID,omitempty"`
Expand All @@ -47,10 +47,10 @@ type CloudStackMachineSpec struct {
// +optional
SSHKey string `json:"sshKey"`

// Optional details map for deployVirtualMachine
// Optional details map for deployVirtualMachine.
Details map[string]string `json:"details,omitempty"`

// Optional affinitygroupids for deployVirtualMachine
// Optional affinitygroupids for deployVirtualMachine.
// +optional
AffinityGroupIds []string `json:"affinitygroupids,omitempty"`

Expand All @@ -59,27 +59,24 @@ type CloudStackMachineSpec struct {
// +optional
Affinity string `json:"affinity,omitempty"`

// The CS specific unique identifier. Of the form: fmt.Sprintf("cloudstack:///%s", CS Machine Id)
// The CS specific unique identifier. Of the form: fmt.Sprintf("cloudstack:///%s", CS Machine Id).
// +optional
ProviderID *string `json:"providerID,omitempty"`

// IdentityRef is a reference to a identity to be used when reconciling this cluster
// IdentityRef is a reference to a identity to be used when reconciling this cluster.
// +optional
// +k8s:conversion-gen=false
IdentityRef *CloudStackIdentityReference `json:"identityRef,omitempty"`
}

// TODO: Review the use of this field/type.
type InstanceState string

// Type pulled mostly from the CloudStack API.
// CloudStackMachineStatus type pulled mostly from the CloudStack API.
type CloudStackMachineStatus struct {
// Addresses contains a CloudStack VM instance's IP addresses.
Addresses []corev1.NodeAddress `json:"addresses,omitempty"`

// InstanceState is the state of the CloudStack instance for this machine.
// +optional
InstanceState InstanceState `json:"instanceState,omitempty"`
InstanceState string `json:"instanceState,omitempty"`

// Ready indicates the readiness of the provider resource.
Ready bool `json:"ready"`
Expand All @@ -95,7 +92,7 @@ type CloudStackMachineStatus struct {
// +kubebuilder:printcolumn:name="ProviderID",type="string",JSONPath=".spec.providerID",description="CloudStack instance ID"
// +kubebuilder:printcolumn:name="Machine",type="string",JSONPath=".metadata.ownerReferences[?(@.kind==\"Machine\")].name",description="Machine object which owns with this CloudStackMachine"

// CloudStackMachine is the Schema for the cloudstackmachines API
// CloudStackMachine is the Schema for the cloudstackmachines API.
type CloudStackMachine struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -104,7 +101,7 @@ type CloudStackMachine struct {
Status CloudStackMachineStatus `json:"status,omitempty"`
}

// The computed affinity group name relevant to this machine.
// AffinityGroupName generates the affinity group name relevant to this machine.
func (csm CloudStackMachine) AffinityGroupName(
capiMachine *capiv1.Machine,
) (string, error) {
Expand All @@ -118,7 +115,7 @@ func (csm CloudStackMachine) AffinityGroupName(

//+kubebuilder:object:root=true

// CloudStackMachineList contains a list of CloudStackMachine
// CloudStackMachineList contains a list of CloudStackMachine.
type CloudStackMachineList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
9 changes: 5 additions & 4 deletions api/v1beta1/cloudstackmachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
// log is for logging in this package.
var cloudstackmachinelog = logf.Log.WithName("cloudstackmachine-resource")

// SetupWebhookWithManager creates a new webhook managed by passed manager.
func (r *CloudStackMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Expand All @@ -42,7 +43,7 @@ func (r *CloudStackMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {

var _ webhook.Defaulter = &CloudStackMachine{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (r *CloudStackMachine) Default() {
cloudstackmachinelog.Info("default", "name", r.Name)
// No defaulted values supported yet.
Expand All @@ -52,7 +53,7 @@ func (r *CloudStackMachine) Default() {

var _ webhook.Validator = &CloudStackMachine{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackMachine) ValidateCreate() error {
cloudstackmachinelog.Info("validate create", "name", r.Name)

Expand All @@ -69,7 +70,7 @@ func (r *CloudStackMachine) ValidateCreate() error {
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackMachine) ValidateUpdate(old runtime.Object) error {
cloudstackmachinelog.Info("validate update", "name", r.Name)

Expand Down Expand Up @@ -100,7 +101,7 @@ func (r *CloudStackMachine) ValidateUpdate(old runtime.Object) error {
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackMachine) ValidateDelete() error {
cloudstackmachinelog.Info("validate delete", "name", r.Name)
// No deletion validations. Deletion webhook not enabled.
Expand Down
9 changes: 5 additions & 4 deletions api/v1beta1/cloudstackmachinetemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// CloudStackMachineTemplateResource defines the desired spec of CloudStackMachine.
type CloudStackMachineTemplateResource struct {
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata.
// +optional
ObjectMeta metav1.ObjectMeta `json:"metadata,omitempty"`
Spec CloudStackMachineSpec `json:"spec"`
}

// CloudStackMachineTemplateSpec defines the desired state of CloudStackMachineTemplate
// CloudStackMachineTemplateSpec defines the desired state of CloudStackMachineTemplate.
type CloudStackMachineTemplateSpec struct {
Spec CloudStackMachineTemplateResource `json:"template"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// CloudStackMachineTemplate is the Schema for the cloudstackmachinetemplates API
// CloudStackMachineTemplate is the Schema for the cloudstackmachinetemplates API.
type CloudStackMachineTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -46,7 +47,7 @@ type CloudStackMachineTemplate struct {

//+kubebuilder:object:root=true

// CloudStackMachineTemplateList contains a list of CloudStackMachineTemplate
// CloudStackMachineTemplateList contains a list of CloudStackMachineTemplate.
type CloudStackMachineTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
13 changes: 7 additions & 6 deletions api/v1beta1/cloudstackmachinetemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
// log is for logging in this package.
var cloudstackmachinetemplatelog = logf.Log.WithName("cloudstackmachinetemplate-resource")

// SetupWebhookWithManager creates a new webhook managed by passed manager.
func (r *CloudStackMachineTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Expand All @@ -42,7 +43,7 @@ func (r *CloudStackMachineTemplate) SetupWebhookWithManager(mgr ctrl.Manager) er
//+kubebuilder:webhook:path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-cloudstackmachinetemplate,mutating=true,failurePolicy=fail,sideEffects=None,groups=infrastructure.cluster.x-k8s.io,resources=cloudstackmachinetemplates,verbs=create;update,versions=v1beta1,name=mcloudstackmachinetemplate.kb.io,admissionReviewVersions=v1beta1
var _ webhook.Defaulter = &CloudStackMachineTemplate{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (r *CloudStackMachineTemplate) Default() {
cloudstackmachinetemplatelog.Info("default", "name", r.Name)
// No defaulted values supported yet.
Expand All @@ -52,13 +53,13 @@ func (r *CloudStackMachineTemplate) Default() {

var _ webhook.Validator = &CloudStackMachineTemplate{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackMachineTemplate) ValidateCreate() error {
cloudstackmachinetemplatelog.Info("validate create", "name", r.Name)

var (
errorList field.ErrorList
spec = r.Spec.Spec.Spec // CloudStackMachineTemplateSpec.CloudStackMachineTemplateResource.CloudStackMachineSpec
spec = r.Spec.Spec.Spec // CloudStackMachineTemplateSpec.CloudStackMachineTemplateResource.CloudStackMachineSpec.
)

// IdentityRefs must be Secrets.
Expand All @@ -82,13 +83,13 @@ func (r *CloudStackMachineTemplate) ValidateCreate() error {
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackMachineTemplate) ValidateUpdate(old runtime.Object) error {
cloudstackmachinetemplatelog.Info("validate update", "name", r.Name)

var (
errorList field.ErrorList
spec = r.Spec.Spec.Spec // CloudStackMachineTemplateSpec.CloudStackMachineTemplateResource.CloudStackMachineSpec
spec = r.Spec.Spec.Spec // CloudStackMachineTemplateSpec.CloudStackMachineTemplateResource.CloudStackMachineSpec.
)

oldMachineTemplate, ok := old.(*CloudStackMachineTemplate)
Expand Down Expand Up @@ -118,7 +119,7 @@ func (r *CloudStackMachineTemplate) ValidateUpdate(old runtime.Object) error {
return webhookutil.AggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, errorList)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackMachineTemplate) ValidateDelete() error {
cloudstackmachinetemplatelog.Info("validate delete", "name", r.Name)
// No deletion validations. Deletion webhook not enabled.
Expand Down
6 changes: 3 additions & 3 deletions api/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1beta1 contains API Schema definitions for the infrastructure v1beta1 API group
// Package v1beta1 contains API Schema definitions for the infrastructure v1beta1 API group.
//+kubebuilder:object:generate=true
//+groupName=infrastructure.cluster.x-k8s.io
package v1beta1
Expand All @@ -25,10 +25,10 @@ import (
)

var (
// GroupVersion is group version used to register these objects
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "infrastructure.cluster.x-k8s.io", Version: "v1beta1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())

// start webhook server using Manager
// start webhook server using Manager.
webhookInstallOptions := &testEnv.WebhookInstallOptions
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
Expand Down Expand Up @@ -117,7 +117,7 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
}()

// wait for the webhook server to get ready
// wait for the webhook server to get ready.
dialer := &net.Dialer{Timeout: time.Second}
addrPort := fmt.Sprintf("%s:%d", webhookInstallOptions.LocalServingHost, webhookInstallOptions.LocalServingPort)
Eventually(func() error {
Expand Down
Loading