Skip to content

Commit

Permalink
enable unparam
Browse files Browse the repository at this point in the history
  • Loading branch information
k15r committed Dec 19, 2023
1 parent 6ae3528 commit a614dc1
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 33 deletions.
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ linters:
- testpackage
- tparallel
- unconvert
- unparam
- varnamelen
- wrapcheck

Expand Down
3 changes: 1 addition & 2 deletions internal/controller/operator/eventing/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ func (r *Reconciler) handleEventingReconcile(ctx context.Context,
r.InitStateProcessing(eventing)
if eventing.Spec.Backend == nil {
return kctrl.Result{Requeue: true}, r.syncStatusForEmptyBackend(ctx,
operatorv1alpha1.ConditionReasonBackendNotSpecified,
operatorv1alpha1.ConditionBackendNotSpecifiedMessage,
eventing, log)
}
Expand Down Expand Up @@ -563,7 +562,7 @@ func (r *Reconciler) reconcileNATSBackend(ctx context.Context, eventing *operato
}

// start NATS subscription manager
if err := r.reconcileNATSSubManager(ctx, eventing, log); err != nil {
if err := r.reconcileNATSSubManager(eventing, log); err != nil {
return kctrl.Result{}, r.syncStatusWithNATSErr(ctx, eventing, err, log)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/operator/eventing/eventmesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (r *Reconciler) checkDomain(ctx context.Context, domain string) (string, er
shootInfoConfigMapNamespace, shootInfoConfigMapName,
)
cmDomain, err := r.readDomainFromConfigMap(ctx)
if err != nil || utils.IsEmpty(domain) {
if err != nil || utils.IsEmpty(cmDomain) {
return "", domainMissingError(err)
}
ret = cmDomain
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/operator/eventing/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

var ErrCannotBuildNATSURL = errors.New("NATS CR is not found to build NATS server URL")

func (r *Reconciler) reconcileNATSSubManager(ctx context.Context, eventing *v1alpha1.Eventing, log *zap.SugaredLogger) error {
func (r *Reconciler) reconcileNATSSubManager(eventing *v1alpha1.Eventing, log *zap.SugaredLogger) error {
// get the subscription config
defaultSubsConfig := r.getDefaultSubscriptionConfig()
// get the nats config
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/operator/eventing/nats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ func Test_reconcileNATSSubManager(t *testing.T) {
givenEventing.Status.BackendConfigHash = tc.givenHashBefore

// when
err := testEnv.Reconciler.reconcileNATSSubManager(context.Background(), givenEventing, logger)
err := testEnv.Reconciler.reconcileNATSSubManager(givenEventing, logger)
if err != nil && tc.givenShouldRetry {
// This is to test the scenario where initialization of natsSubManager was successful but
// starting the natsSubManager failed. So on next try it should again try to start the natsSubManager.
err = testEnv.Reconciler.reconcileNATSSubManager(context.Background(), givenEventing, logger)
err = testEnv.Reconciler.reconcileNATSSubManager(givenEventing, logger)
}
if tc.givenUpdateTest {
// Run reconcile again with newBackendConfig:
err = testEnv.Reconciler.reconcileNATSSubManager(context.Background(), givenEventing, logger)
err = testEnv.Reconciler.reconcileNATSSubManager(givenEventing, logger)
require.NoError(t, err)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/operator/eventing/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r *Reconciler) syncStatusWithNATSState(ctx context.Context, state string,
return errors.Join(err, r.syncEventingStatus(ctx, eventing, log))
}

func (r *Reconciler) syncStatusForEmptyBackend(ctx context.Context, reason operatorv1alpha1.ConditionReason,
func (r *Reconciler) syncStatusForEmptyBackend(ctx context.Context,
message string, eventing *operatorv1alpha1.Eventing, log *zap.SugaredLogger,
) error {
// Set error state in status
Expand Down
27 changes: 9 additions & 18 deletions pkg/backend/utils/eventmesh_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ func hashSubscriptionFullName(domainName, namespace, name string) string {
return hex.EncodeToString(hash[:])
}

func getDefaultSubscriptionV1Alpha2(protocolSettings *ProtocolSettings) (*types.Subscription, error) {
func getDefaultSubscriptionV1Alpha2(protocolSettings *ProtocolSettings) *types.Subscription {
// @TODO: Rename this method to getDefaultSubscription once old BEB backend is depreciated
emsSubscription := &types.Subscription{}
emsSubscription.ContentMode = *protocolSettings.ContentMode
emsSubscription.ExemptHandshake = *protocolSettings.ExemptHandshake
emsSubscription.Qos = types.GetQos(*protocolSettings.Qos)
return emsSubscription, nil
return emsSubscription
}

func getEventMeshEvents(typeInfos []EventTypeInfo, typeMatching eventingv1alpha2.TypeMatching,
Expand Down Expand Up @@ -115,17 +115,12 @@ func ConvertKymaSubToEventMeshSub(
nameMapper NameMapper,
) (*types.Subscription, error) {
// get default EventMesh subscription object
eventMeshSubscription, err := getDefaultSubscriptionV1Alpha2(defaultProtocolSettings)
if err != nil {
return nil, errors.Wrap(err, "apply default protocol settings failed")
}
eventMeshSubscription := getDefaultSubscriptionV1Alpha2(defaultProtocolSettings)
// set Name of EventMesh subscription
eventMeshSubscription.Name = nameMapper.MapSubscriptionName(subscription.Name, subscription.Namespace)

// Applying protocol settings if provided in subscription CR
if setErr := setEventMeshProtocolSettings(subscription, eventMeshSubscription); setErr != nil {
return nil, setErr
}
setEventMeshProtocolSettings(subscription, eventMeshSubscription)

// Events
// set the event types in EventMesh subscription instance
Expand All @@ -141,15 +136,12 @@ func ConvertKymaSubToEventMeshSub(
eventMeshSubscription.WebhookURL = urlTobeRegistered

// set webhook auth
eventMeshSubscription.WebhookAuth, err = getEventMeshWebhookAuth(subscription, defaultWebhookAuth)
if err != nil {
return nil, err
}
eventMeshSubscription.WebhookAuth = getEventMeshWebhookAuth(subscription, defaultWebhookAuth)

return eventMeshSubscription, nil
}

func setEventMeshProtocolSettings(subscription *eventingv1alpha2.Subscription, eventMeshSub *types.Subscription) error {
func setEventMeshProtocolSettings(subscription *eventingv1alpha2.Subscription, eventMeshSub *types.Subscription) {
// Applying protocol settings if provided in subscription CR
// qos
if qosStr, ok := subscription.Spec.Config[eventingv1alpha2.ProtocolSettingsQos]; ok {
Expand All @@ -167,20 +159,19 @@ func setEventMeshProtocolSettings(subscription *eventingv1alpha2.Subscription, e
}
eventMeshSub.ExemptHandshake = handshake
}
return nil
}

// getEventMeshWebhookAuth uses default webhook auth unless specified in Subscription CR.
func getEventMeshWebhookAuth(subscription *eventingv1alpha2.Subscription,
defaultWebhookAuth *types.WebhookAuth,
) (*types.WebhookAuth, error) {
) *types.WebhookAuth {
auth := &types.WebhookAuth{}
// extract auth info from subscription CR if any
if authType, ok := subscription.Spec.Config[eventingv1alpha2.WebhookAuthType]; ok {
auth.Type = types.GetAuthType(authType)
} else {
// if auth type was not provided then use default webhook auth
return defaultWebhookAuth, nil
return defaultWebhookAuth
}

if grantType, ok := subscription.Spec.Config[eventingv1alpha2.WebhookAuthGrantType]; ok {
Expand All @@ -199,7 +190,7 @@ func getEventMeshWebhookAuth(subscription *eventingv1alpha2.Subscription,
auth.ClientSecret = clientSecret
}

return auth, nil
return auth
}

func GetCleanedEventMeshSubscription(subscription *types.Subscription) *types.Subscription {
Expand Down
6 changes: 2 additions & 4 deletions pkg/backend/utils/eventmesh_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,9 @@ func Test_setEventMeshProtocolSettings(t *testing.T) {
eventMeshSubscription := tc.givenEventMeshSubscription

// when
err := setEventMeshProtocolSettings(tc.givenSubscription, eventMeshSubscription)
setEventMeshProtocolSettings(tc.givenSubscription, eventMeshSubscription)

// then
require.NoError(t, err)
require.Equal(t, tc.wantEventMeshSubscription, eventMeshSubscription)
})
}
Expand Down Expand Up @@ -283,10 +282,9 @@ func Test_getEventMeshWebhookAuth(t *testing.T) {
// given

// when
webhookAuth, err := getEventMeshWebhookAuth(tc.givenSubscription, defaultWebhookAuth)
webhookAuth := getEventMeshWebhookAuth(tc.givenSubscription, defaultWebhookAuth)

// then
require.NoError(t, err)
require.Equal(t, tc.wantWebhook, webhookAuth)
})
}
Expand Down
4 changes: 2 additions & 2 deletions test/utils/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import (

const (
useExistingCluster = false
attachControlPlaneOutput = false
attachControlPlaneOutput = true
testEnvStartDelay = time.Minute
testEnvStartAttempts = 10
BigPollingInterval = 3 * time.Second
Expand Down Expand Up @@ -316,7 +316,7 @@ func SetupAndStartEnvTest(config TestEnvironmentConfig) (*envtest.Environment, *
}

args := testEnv.ControlPlane.GetAPIServer().Configure()
args.Set("feature-gates", "CustomResourceValidationExpressions=%s", strconv.FormatBool(config.CELValidationEnabled))
args.Set("feature-gates", fmt.Sprintf("CustomResourceValidationExpressions=%s", strconv.FormatBool(config.CELValidationEnabled)))

cfg, err := StartEnvTestWithRetry(testEnv)
return testEnv, cfg, err
Expand Down

0 comments on commit a614dc1

Please sign in to comment.