Skip to content

Commit

Permalink
Merge pull request #298 from gibizer/full-golangci-lint
Browse files Browse the repository at this point in the history
Ensure golangci-lint runs on all files
  • Loading branch information
openshift-merge-bot[bot] authored Apr 26, 2024
2 parents 7825023 + b53642c commit 481577e
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.55.2
hooks:
- id: golangci-lint
- id: golangci-lint-full
args: ["-v"]
19 changes: 8 additions & 11 deletions controllers/amphoracontroller_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
nad "github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment"
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
Expand Down Expand Up @@ -206,16 +205,14 @@ func (r *OctaviaAmphoraControllerReconciler) reconcileDelete(ctx context.Context
return ctrl.Result{}, nil
}

func (r *OctaviaAmphoraControllerReconciler) reconcileUpdate(ctx context.Context, instance *octaviav1.OctaviaAmphoraController,
helper *helper.Helper) (ctrl.Result, error) {
func (r *OctaviaAmphoraControllerReconciler) reconcileUpdate(ctx context.Context) (ctrl.Result, error) {
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service update")
Log.Info("Reconciled Service update successfully")
return ctrl.Result{}, nil
}

func (r *OctaviaAmphoraControllerReconciler) reconcileUpgrade(ctx context.Context, instance *octaviav1.OctaviaAmphoraController,
helper *helper.Helper) (ctrl.Result, error) {
func (r *OctaviaAmphoraControllerReconciler) reconcileUpgrade(ctx context.Context) (ctrl.Result, error) {
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service upgrade")
Log.Info("Reconciled Service upgrade successfully")
Expand Down Expand Up @@ -393,15 +390,15 @@ func (r *OctaviaAmphoraControllerReconciler) reconcileNormal(ctx context.Context
instance.Status.Conditions.MarkTrue(condition.ServiceConfigReadyCondition, condition.ServiceConfigReadyMessage)

// Handle service update
ctrlResult, err := r.reconcileUpdate(ctx, instance, helper)
ctrlResult, err := r.reconcileUpdate(ctx)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
return ctrlResult, nil
}

// Handle service upgrade
ctrlResult, err = r.reconcileUpgrade(ctx, instance, helper)
ctrlResult, err = r.reconcileUpgrade(ctx)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
Expand Down Expand Up @@ -578,7 +575,7 @@ func (r *OctaviaAmphoraControllerReconciler) generateServiceConfigMaps(
parentOctaviaName := octavia.GetOwningOctaviaControllerName(
instance)
serverCAPassSecretName := fmt.Sprintf("%s-ca-passphrase", parentOctaviaName)
caPassSecret, _, err := secret.GetSecret(
caPassSecret, _, err := oko_secret.GetSecret(
ctx, helper, serverCAPassSecretName, instance.Namespace)
if err != nil {
if k8s_errors.IsNotFound(err) {
Expand Down Expand Up @@ -681,7 +678,7 @@ func (r *OctaviaAmphoraControllerReconciler) generateServiceConfigMaps(
},
}

err = secret.EnsureSecrets(ctx, helper, instance, cms, envVars)
err = oko_secret.EnsureSecrets(ctx, helper, instance, cms, envVars)
if err != nil {
r.Log.Error(err, "unable to process config map")
return err
Expand Down Expand Up @@ -795,15 +792,15 @@ func getPodIPs(name string, ns string, client kubernetes.Interface, log *logr.Lo
func (r *OctaviaAmphoraControllerReconciler) findObjectsForSrc(ctx context.Context, src client.Object) []reconcile.Request {
requests := []reconcile.Request{}

l := log.FromContext(context.Background()).WithName("Controllers").WithName("Amphora")
l := log.FromContext(ctx).WithName("Controllers").WithName("Amphora")

for _, field := range allWatchFields {
crList := &octaviav1.OctaviaAmphoraControllerList{}
listOps := &client.ListOptions{
FieldSelector: fields.OneTermEqualSelector(field, src.GetName()),
Namespace: src.GetNamespace(),
}
err := r.Client.List(context.TODO(), crList, listOps)
err := r.Client.List(ctx, crList, listOps)
if err != nil {
return []reconcile.Request{}
}
Expand Down
36 changes: 18 additions & 18 deletions controllers/octavia_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
nad "github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment"
common_rbac "github.com/openstack-k8s-operators/lib-common/modules/common/rbac"
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
oko_secret "github.com/openstack-k8s-operators/lib-common/modules/common/secret"
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
Expand Down Expand Up @@ -429,7 +428,7 @@ func (r *OctaviaReconciler) reconcileInit(
return ctrl.Result{}, nil
}

func (r *OctaviaReconciler) reconcileUpdate(ctx context.Context, instance *octaviav1.Octavia, helper *helper.Helper) (ctrl.Result, error) {
func (r *OctaviaReconciler) reconcileUpdate(ctx context.Context) (ctrl.Result, error) {
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service update")

Expand All @@ -440,7 +439,7 @@ func (r *OctaviaReconciler) reconcileUpdate(ctx context.Context, instance *octav
return ctrl.Result{}, nil
}

func (r *OctaviaReconciler) reconcileUpgrade(ctx context.Context, instance *octaviav1.Octavia, helper *helper.Helper) (ctrl.Result, error) {
func (r *OctaviaReconciler) reconcileUpgrade(ctx context.Context) (ctrl.Result, error) {
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service upgrade")

Expand Down Expand Up @@ -572,15 +571,15 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)

// Handle service update
ctrlResult, err = r.reconcileUpdate(ctx, instance, helper)
ctrlResult, err = r.reconcileUpdate(ctx)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
return ctrlResult, nil
}

// Handle service upgrade
ctrlResult, err = r.reconcileUpgrade(ctx, instance, helper)
ctrlResult, err = r.reconcileUpgrade(ctx)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
Expand Down Expand Up @@ -649,7 +648,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
}
Log.Info(fmt.Sprintf("Using management network \"%s\"", networkInfo.TenantNetworkID))

ampImageOwnerID, err := octavia.GetImageOwnerID(ctx, instance, &Log, helper)
ampImageOwnerID, err := octavia.GetImageOwnerID(ctx, instance, helper)
if err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -773,7 +772,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
}

// Amphora SSH key config for debugging
err = octavia.EnsureAmpSSHConfig(ctx, instance, helper, &Log)
err = octavia.EnsureAmpSSHConfig(ctx, instance, helper)
if err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -1044,7 +1043,7 @@ func (r *OctaviaReconciler) reconcileAmphoraImages(
return ctrl.Result{}, err
}

urlMap, err := r.getLocalImageURLs(ctx, helper, endpoint)
urlMap, err := r.getLocalImageURLs(endpoint)
if err != nil {
Log.Info(fmt.Sprintf("Cannot get amphora image list: %s", err))
return ctrl.Result{Requeue: true, RequeueAfter: 1 * time.Second}, err
Expand All @@ -1062,33 +1061,34 @@ func (r *OctaviaReconciler) reconcileAmphoraImages(
Log.Info(fmt.Sprintf("Setting image upload hash - %s", hash))
instance.Status.Hash[octaviav1.ImageUploadHash] = hash

// Tasks are successfull, the deployment can be deleted
// Tasks are successful, the deployment can be deleted
Log.Info("Deleting amphora image upload deployment")
depl.Delete(ctx, helper)
err = depl.Delete(ctx, helper)
if err != nil {
return ctrl.Result{}, err
}

return ctrl.Result{}, nil
}

func (r *OctaviaReconciler) getLocalImageURLs(
ctx context.Context,
helper *helper.Helper,
endpoint string,
) ([]octavia.OctaviaAmphoraImage, error) {
) ([]octavia.AmphoraImage, error) {
// Get the list of images and their hashes
listUrl := fmt.Sprintf("%s/octavia-amphora-images.sha256sum", endpoint)
listURL := fmt.Sprintf("%s/octavia-amphora-images.sha256sum", endpoint)

resp, err := http.Get(listUrl)
resp, err := http.Get(listURL)
if err != nil {
return nil, err
}
defer resp.Body.Close()
scanner := bufio.NewScanner(resp.Body)
ret := []octavia.OctaviaAmphoraImage{}
ret := []octavia.AmphoraImage{}
for scanner.Scan() {
fields := strings.Fields(scanner.Text())
if len(fields) == 2 {
name, _ := strings.CutSuffix(fields[1], ".qcow2")
ret = append(ret, octavia.OctaviaAmphoraImage{
ret = append(ret, octavia.AmphoraImage{
Name: name,
URL: fmt.Sprintf("%s/%s", endpoint, fields[1]),
Checksum: fields[0],
Expand Down Expand Up @@ -1180,7 +1180,7 @@ func (r *OctaviaReconciler) generateServiceConfigMaps(
Labels: cmLabels,
},
}
err := secret.EnsureSecrets(ctx, h, instance, cms, envVars)
err := oko_secret.EnsureSecrets(ctx, h, instance, cms, envVars)
if err != nil {
return err
}
Expand Down
15 changes: 7 additions & 8 deletions controllers/octaviaapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
nad "github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment"
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
oko_secret "github.com/openstack-k8s-operators/lib-common/modules/common/secret"
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
Expand Down Expand Up @@ -280,15 +279,15 @@ func (r *OctaviaAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
func (r *OctaviaAPIReconciler) findObjectsForSrc(ctx context.Context, src client.Object) []reconcile.Request {
requests := []reconcile.Request{}

l := log.FromContext(context.Background()).WithName("Controllers").WithName("OctaviaAPI")
l := log.FromContext(ctx).WithName("Controllers").WithName("OctaviaAPI")

for _, field := range allWatchFields {
crList := &octaviav1.OctaviaAPIList{}
listOps := &client.ListOptions{
FieldSelector: fields.OneTermEqualSelector(field, src.GetName()),
Namespace: src.GetNamespace(),
}
err := r.Client.List(context.TODO(), crList, listOps)
err := r.Client.List(ctx, crList, listOps)
if err != nil {
return []reconcile.Request{}
}
Expand Down Expand Up @@ -531,7 +530,7 @@ func (r *OctaviaAPIReconciler) reconcileInit(
return ctrlResult, nil
}

func (r *OctaviaAPIReconciler) reconcileUpdate(ctx context.Context, instance *octaviav1.OctaviaAPI, helper *helper.Helper) (ctrl.Result, error) {
func (r *OctaviaAPIReconciler) reconcileUpdate(ctx context.Context) (ctrl.Result, error) {
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service update")

Expand All @@ -542,7 +541,7 @@ func (r *OctaviaAPIReconciler) reconcileUpdate(ctx context.Context, instance *oc
return ctrl.Result{}, nil
}

func (r *OctaviaAPIReconciler) reconcileUpgrade(ctx context.Context, instance *octaviav1.OctaviaAPI, helper *helper.Helper) (ctrl.Result, error) {
func (r *OctaviaAPIReconciler) reconcileUpgrade(ctx context.Context) (ctrl.Result, error) {
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service upgrade")

Expand Down Expand Up @@ -739,15 +738,15 @@ func (r *OctaviaAPIReconciler) reconcileNormal(ctx context.Context, instance *oc
}

// Handle service update
ctrlResult, err = r.reconcileUpdate(ctx, instance, helper)
ctrlResult, err = r.reconcileUpdate(ctx)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
return ctrlResult, nil
}

// Handle service upgrade
ctrlResult, err = r.reconcileUpgrade(ctx, instance, helper)
ctrlResult, err = r.reconcileUpgrade(ctx)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
Expand Down Expand Up @@ -999,7 +998,7 @@ func (r *OctaviaAPIReconciler) generateServiceConfigMaps(
Labels: cmLabels,
},
}
err = secret.EnsureSecrets(ctx, h, instance, cms, envVars)
err = oko_secret.EnsureSecrets(ctx, h, instance, cms, envVars)

if err != nil {
Log.Error(err, "unable to process config map")
Expand Down
4 changes: 2 additions & 2 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"path/filepath"
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/v2" //revive:disable:dot-imports
. "github.com/onsi/gomega" //revive:disable:dot-imports

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
Expand Down
6 changes: 3 additions & 3 deletions pkg/octavia/amphora_certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func generateCACert(caPrivKey *rsa.PrivateKey, commonName string) ([]byte, *x509
}

// Create a certificate and key for the client and sign it with the CA
func generateClientCert(caCertPEM []byte, caTemplate *x509.Certificate, certPrivKey *rsa.PrivateKey, caPrivKey *rsa.PrivateKey, commonName string) ([]byte, error) {
func generateClientCert(caTemplate *x509.Certificate, certPrivKey *rsa.PrivateKey, caPrivKey *rsa.PrivateKey, commonName string) ([]byte, error) {

certTemplate := &x509.Certificate{
SerialNumber: big.NewInt(2019),
Expand Down Expand Up @@ -152,7 +152,7 @@ func EnsureAmphoraCerts(
h *helper.Helper,
log *logr.Logger) error {
var oAmpSecret *corev1.Secret
var serverCAPass []byte = nil
var serverCAPass []byte

certsSecretName := fmt.Sprintf("%s-certs-secret", instance.Name)
_, _, err := secret.GetSecret(ctx, h, certsSecretName, instance.Namespace)
Expand Down Expand Up @@ -192,7 +192,7 @@ func EnsureAmphoraCerts(
if err != nil {
return fmt.Errorf("Error while generating amphora client key: %w", err)
}
clientCert, err := generateClientCert(clientCACert, clientCATemplate, clientKey, clientCAKey, "Octavia controller")
clientCert, err := generateClientCert(clientCATemplate, clientKey, clientCAKey, "Octavia controller")
if err != nil {
return fmt.Errorf("Error while generating amphora client certificate: %w", err)
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/octavia/amphora_ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"fmt"
"time"

"github.com/go-logr/logr"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
"github.com/openstack-k8s-operators/lib-common/modules/common/configmap"
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
Expand Down Expand Up @@ -141,7 +140,7 @@ func uploadKeypair(
return fmt.Errorf("Could not extract keypairs: %w", err)
}

var keypairExists bool = false
var keypairExists = false
for _, kp := range allKeyPairs {
if kp.Name == NovaKeyPairName {
keypairExists = true
Expand Down Expand Up @@ -177,7 +176,6 @@ func EnsureAmpSSHConfig(
ctx context.Context,
instance *octaviav1.Octavia,
h *helper.Helper,
log *logr.Logger,
) error {
cmap, _, err := configmap.GetConfigMap(
ctx, h, instance, instance.Spec.LoadBalancerSSHPubKey, 10*time.Second)
Expand Down
4 changes: 2 additions & 2 deletions pkg/octavia/image_upload_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func getInitVolumeMounts() []corev1.VolumeMount {
}

// GetVolumeMounts - general VolumeMounts
func getVolumeMounts(serviceName string) []corev1.VolumeMount {
func getVolumeMounts() []corev1.VolumeMount {
return []corev1.VolumeMount{
{
Name: "amphora-image",
Expand Down Expand Up @@ -116,7 +116,7 @@ func ImageUploadDeployment(
},
Args: args,
Image: instance.Spec.ApacheContainerImage,
VolumeMounts: getVolumeMounts("octavia-image-upload"),
VolumeMounts: getVolumeMounts(),
Resources: instance.Spec.Resources,
// TODO(gthiemonge) do we need probes?
},
Expand Down
Loading

0 comments on commit 481577e

Please sign in to comment.