Skip to content

Commit

Permalink
Merge pull request #102 from inteon/fix_linters
Browse files Browse the repository at this point in the history
Fix linters
  • Loading branch information
jetstack-bot authored Apr 3, 2024
2 parents 914487e + 2cf3e86 commit e9d8b94
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 40 deletions.
5 changes: 0 additions & 5 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ issues:
exclude-rules:
- linters:
- gosec
- unparam
- errorlint
- tenv
- gci
- gocritic
text: ".*"
linters:
# Explicitly define all enabled linters
Expand Down
8 changes: 4 additions & 4 deletions controllers/certificaterequest_controller_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestCertificateRequestControllerIntegrationIssuerInitiallyNotFoundAndNotRea

checkComplete := kubeClients.StartObjectWatch(t, ctx, cr)
t.Log("Creating & approving the CertificateRequest")
createApprovedCR(t, ctx, kubeClients.Client, clock.RealClock{}, cr)
createApprovedCR(t, ctx, kubeClients.Client, cr)
t.Log("Waiting for controller to mark the CertificateRequest as IssuerNotFound")
err := checkComplete(func(obj runtime.Object) error {
readyCondition := cmutil.GetCertificateRequestCondition(obj.(*cmapi.CertificateRequest), cmapi.CertificateRequestConditionReady)
Expand Down Expand Up @@ -272,7 +272,7 @@ func TestCertificateRequestControllerIntegrationSetCondition(t *testing.T) {

checkComplete := kubeClients.StartObjectWatch(t, ctx, cr)
t.Log("Creating & approving the CertificateRequest")
createApprovedCR(t, ctx, kubeClients.Client, clock.RealClock{}, cr)
createApprovedCR(t, ctx, kubeClients.Client, cr)
t.Log("Waiting for controller to mark the CertificateRequest as IssuerNotFound")
err := checkComplete(func(obj runtime.Object) error {
readyCondition := cmutil.GetCertificateRequestCondition(obj.(*cmapi.CertificateRequest), cmapi.CertificateRequestConditionReady)
Expand Down Expand Up @@ -372,12 +372,12 @@ func TestCertificateRequestControllerIntegrationSetCondition(t *testing.T) {
require.Equal(t, uint64(3), atomic.LoadUint64(&counter))
}

func createApprovedCR(t *testing.T, ctx context.Context, kc client.Client, clock clock.PassiveClock, cr *cmapi.CertificateRequest) {
func createApprovedCR(t *testing.T, ctx context.Context, kc client.Client, cr *cmapi.CertificateRequest) {
t.Helper()

require.NoError(t, kc.Create(ctx, cr))
conditions.SetCertificateRequestStatusCondition(
clock,
clock.RealClock{},
cr.Status.Conditions,
&cr.Status.Conditions,
cmapi.CertificateRequestConditionApproved,
Expand Down
4 changes: 2 additions & 2 deletions controllers/combined_controller_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestCombinedControllerTemporaryFailedCertificateRequestRetrigger(t *testing
}, watch.Added, watch.Modified)
require.NoError(t, err)

createApprovedCR(t, ctx, kubeClients.Client, clock.RealClock{}, cr)
createApprovedCR(t, ctx, kubeClients.Client, cr)

checkCr1Complete := kubeClients.StartObjectWatch(t, ctx, cr)
checkCr2Complete := kubeClients.StartObjectWatch(t, ctx, cr)
Expand Down Expand Up @@ -538,7 +538,7 @@ func TestCombinedControllerTiming(t *testing.T) { //nolint:tparallel
)

require.NoError(t, kubeClients.Client.Create(ctx, issuer))
createApprovedCR(t, ctx, kubeClients.Client, clock.RealClock{}, cr)
createApprovedCR(t, ctx, kubeClients.Client, cr)

<-done
time.Sleep(1 * time.Second)
Expand Down
21 changes: 8 additions & 13 deletions controllers/issuer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (r *IssuerReconciler) reconcileStatusPatch(
logger logr.Logger,
ctx context.Context,
req ctrl.Request,
) (result ctrl.Result, issuerStatusPatch *v1alpha1.IssuerStatus, reconcileError error) {
) (result ctrl.Result, issuerStatusPatch *v1alpha1.IssuerStatus, reconcileError error) { // nolint:unparam
// Get the ClusterIssuer
issuer := r.ForObject.DeepCopyObject().(v1alpha1.Issuer)
forObjectGvk := r.ForObject.GetObjectKind().GroupVersionKind()
Expand Down Expand Up @@ -170,8 +170,7 @@ func (r *IssuerReconciler) reconcileStatusPatch(
// for updating its Status.
issuerStatusPatch = &v1alpha1.IssuerStatus{}

setCondition := func(
conditionType cmapi.IssuerConditionType,
setReadyCondition := func(
status cmmeta.ConditionStatus,
reason, message string,
) string {
Expand All @@ -180,8 +179,8 @@ func (r *IssuerReconciler) reconcileStatusPatch(
issuer.GetStatus().Conditions,
&issuerStatusPatch.Conditions,
issuer.GetGeneration(),
conditionType, status,
reason, message,
cmapi.IssuerConditionReady,
status, reason, message,
)
return condition.Message
}
Expand All @@ -190,8 +189,7 @@ func (r *IssuerReconciler) reconcileStatusPatch(
// to Unknown.
if readyCondition == nil {
logger.V(1).Info("Initializing Ready condition")
setCondition(
cmapi.IssuerConditionReady,
setReadyCondition(
cmmeta.ConditionUnknown,
v1alpha1.IssuerConditionReasonInitializing,
fmt.Sprintf("%s has started reconciling this Issuer", r.FieldOwner),
Expand All @@ -212,8 +210,7 @@ func (r *IssuerReconciler) reconcileStatusPatch(
}
if err == nil {
logger.V(1).Info("Successfully finished the reconciliation.")
message := setCondition(
cmapi.IssuerConditionReady,
message := setReadyCondition(
cmmeta.ConditionTrue,
v1alpha1.IssuerConditionReasonChecked,
"Succeeded checking the issuer",
Expand All @@ -227,8 +224,7 @@ func (r *IssuerReconciler) reconcileStatusPatch(
if isPermanentError {
// fail permanently
logger.V(1).Error(err, "Permanent Issuer error. Marking as failed.")
message := setCondition(
cmapi.IssuerConditionReady,
message := setReadyCondition(
cmmeta.ConditionFalse,
v1alpha1.IssuerConditionReasonFailed,
fmt.Sprintf("Failed permanently: %s", err),
Expand All @@ -238,8 +234,7 @@ func (r *IssuerReconciler) reconcileStatusPatch(
} else {
// retry
logger.V(1).Error(err, "Retryable Issuer error.")
message := setCondition(
cmapi.IssuerConditionReady,
message := setReadyCondition(
cmmeta.ConditionFalse,
v1alpha1.IssuerConditionReasonPending,
fmt.Sprintf("Not ready yet: %s", err),
Expand Down
1 change: 0 additions & 1 deletion examples/simple/controller/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"time"

ctrl "sigs.k8s.io/controller-runtime"

"simple-issuer/api"

"github.com/cert-manager/issuer-lib/api/v1alpha1"
Expand Down
1 change: 0 additions & 1 deletion examples/simple/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"

"simple-issuer/api"
)

Expand Down
36 changes: 24 additions & 12 deletions examples/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
ctrlzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

"simple-issuer/api"
"simple-issuer/controller"

Expand Down Expand Up @@ -113,6 +112,23 @@ func main() {
klog.SetLogger(logr)
ctrl.SetLogger(logr)

if err := run(
clusterResourceNamespace,
metricsAddr,
enableLeaderElection,
probeAddr,
); err != nil {
logr.Error(err, "error running manager")
os.Exit(1)
}
}

func run(
clusterResourceNamespace string,
metricsAddr string,
enableLeaderElection bool,
probeAddr string,
) error {
setupLog := ctrl.Log.WithName("setup")

setupLog.Info("versionInfo", "Version", Version)
Expand All @@ -124,7 +140,6 @@ func main() {
} else {
setupLog.Error(err, "unexpected error while getting in-cluster Namespace")
}
os.Exit(1)
}

scheme := runtime.NewScheme()
Expand Down Expand Up @@ -160,30 +175,27 @@ func main() {

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
return fmt.Errorf("unable to start manager: %w", err)
}

if err = (&controller.Signer{}).SetupWithManager(ctx, mgr); err != nil {
setupLog.Error(err, "unable to create controller")
os.Exit(1)
return fmt.Errorf("unable to create controller: %w", err)
}
// +kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
return fmt.Errorf("unable to set up health check: %w", err)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
return fmt.Errorf("unable to set up ready check: %w", err)
}

setupLog.Info("starting manager")
if err := mgr.Start(ctx); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
return fmt.Errorf("problem running manager: %w", err)
}

return nil
}

var errNotInCluster = errors.New("not running in-cluster")
Expand Down
3 changes: 1 addition & 2 deletions internal/tests/testresource/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"math/rand"
"os"
goruntime "runtime"
"testing"
"time"
Expand Down Expand Up @@ -107,7 +106,7 @@ func (k *OwnedKubeClients) initTestEnv(tb testing.TB, scheme *runtime.Scheme) {
func (k *OwnedKubeClients) initExistingKubernetes(tb testing.TB, kubeconfig string) {
tb.Helper()

os.Setenv("KUBECONFIG", kubeconfig)
tb.Setenv("KUBECONFIG", kubeconfig)
kubeConfig, err := config.GetConfigWithContext("")
require.NoError(tb, err)

Expand Down

0 comments on commit e9d8b94

Please sign in to comment.