Skip to content

Commit

Permalink
Resolve all existing lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dbason committed Feb 7, 2023
1 parent 5f098ff commit 6286c29
Show file tree
Hide file tree
Showing 105 changed files with 583 additions and 575 deletions.
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ linters-settings:
- name: error-return
- name: error-strings
- name: imports-blacklist
arguments: ["crypto/md5", "crypto/sha1", "grpc.go4.org/**", "github.com/gogo/status","github.com/gogo/codes"]
arguments: ["grpc.go4.org/**", "github.com/gogo/status","github.com/gogo/codes"]
- name: increment-decrement
- name: indent-error-flow
- name: package-comments
Expand Down
8 changes: 4 additions & 4 deletions infra/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func run(ctx *Context) (runErr error) {
}

var id StringOutput
if rand, err := random.NewRandomId(ctx, "id", &random.RandomIdArgs{
rand, err := random.NewRandomId(ctx, "id", &random.RandomIdArgs{
ByteLength: Int(4),
}); err != nil {
})
if err != nil {
return errors.WithStack(err)
} else {
id = rand.Hex
}
id = rand.Hex

tags := map[string]string{}
for k, v := range conf.Tags {
Expand Down
34 changes: 16 additions & 18 deletions pkg/alerting/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,16 @@ func (a *AlertManagerAPI) DoRequest() error {
lastRetrierError := fmt.Errorf("unknwon error")
numRetries := 0
for backoffv2.Continue(b) {
if err := a.doRequest(); err == nil {
err := a.doRequest()
if err == nil {
return nil
} else {
lastRetrierError = err
}
numRetries += 1
lastRetrierError = err
numRetries++
}
return fmt.Errorf("failed to complete request after retrier timeout (%d retries) : %s", numRetries, lastRetrierError)
} else {
return a.doRequest()
}
return a.doRequest()
}

func (a *AlertManagerAPI) doRequest() error {
Expand Down Expand Up @@ -457,20 +456,19 @@ func NewExpectConfigEqual(expectedConfig string) func(*http.Response) error {
func NewApiPipline(ctx context.Context, apis []*AlertManagerAPI, chainRetrier *backoffv2.Policy) error {
if chainRetrier == nil {
return newApiPipeline(apis)
} else {
b := (*chainRetrier).Start(ctx)
lastRetrierError := fmt.Errorf("unkown error")
numRetries := 0
for backoffv2.Continue(b) {
if err := newApiPipeline(apis); err == nil {
return nil
} else {
lastRetrierError = err
}
numRetries += 1
}
b := (*chainRetrier).Start(ctx)
lastRetrierError := fmt.Errorf("unkown error")
numRetries := 0
for backoffv2.Continue(b) {
err := newApiPipeline(apis)
if err == nil {
return nil
}
return fmt.Errorf("api pipeline failed with backoff retrier timeout (%d retries) : %s", numRetries, lastRetrierError)
lastRetrierError = err
numRetries++
}
return fmt.Errorf("api pipeline failed with backoff retrier timeout (%d retries) : %s", numRetries, lastRetrierError)
}

func newApiPipeline(apis []*AlertManagerAPI) error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/alerting/condition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func ParseAlertManagerWebhookPayload(annotations []gjson.Result) ([]*alertingv1.
}
anyFailed := false
res := &alertingv1.TriggerAlertsRequest{}

IDENTIFIERS:
for _, identifier := range RequiredCortexWebhookAnnotationIdentifiers {
if _, ok := result[identifier]; !ok {
errors = append(errors, fmt.Errorf(
Expand All @@ -95,7 +95,7 @@ func ParseAlertManagerWebhookPayload(annotations []gjson.Result) ([]*alertingv1.
errors = append(errors, fmt.Errorf("unhandled opni identifier %s", identifier))
opniRequests = append(opniRequests, nil)
anyFailed = true
break
break IDENTIFIERS
}
}
delete(result, identifier)
Expand Down
4 changes: 2 additions & 2 deletions pkg/alerting/metrics/construct.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ func (a *AlertingRule) Or(other *AlertingRule) AlertRuleBuilder {
}
}

func (a *AlertingRule) IfForSecondsThen(other *AlertingRule, seconds time.Duration) AlertRuleBuilder {
func (a *AlertingRule) IfForSecondsThen(_ *AlertingRule, _ time.Duration) AlertRuleBuilder {
//TODO : implement
return nil
}

func (a *AlertingRule) IfNotForSecondsThen(other *AlertingRule, seconds time.Duration) AlertRuleBuilder {
func (a *AlertingRule) IfNotForSecondsThen(_ *AlertingRule, _ time.Duration) AlertRuleBuilder {
//TODO: implement
return nil
}
Expand Down
36 changes: 17 additions & 19 deletions pkg/alerting/metrics/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import (
_ "embed"
"fmt"
"reflect"
"time"

corev1 "github.com/rancher/opni/pkg/apis/core/v1"
"github.com/rancher/opni/pkg/validation"
"github.com/rancher/opni/plugins/metrics/pkg/apis/cortexadmin"
)
Expand All @@ -33,44 +31,44 @@ type MetricOpts interface {
// Iterates over the field values of the MetricOpts struct
// - Fetches labels and annotations from the field tags
// - Returns a map of options to their list of values
func FetchAlertConditionValues(m *MetricOpts, client *cortexadmin.CortexAdminClient) (interface{}, error) {
func FetchAlertConditionValues(m *MetricOpts, _ *cortexadmin.CortexAdminClient) (interface{}, error) {
values := make(map[string][]string)
t := reflect.TypeOf(m)

for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
labelTag := field.Tag.Get(labelTag)
metricTag := field.Tag.Get(metricTag)
jobExtractorTag := field.Tag.Get(jobExtractorTag)
//jobExtractorTag := field.Tag.Get(jobExtractorTag)
if labelTag != "" {
if metricTag == "" {
panic(fmt.Sprintf("invalid struct declaration for : %s, missing metric tag %s on field", t.Kind(), field.Type.String()))
}
// fetch label values of on metric
}

if field.Tag.Get(jobExtractorTag) != "" {
// get all metric names matching regex expr
}
// if field.Tag.Get(jobExtractorTag) != "" {
// get all metric names matching regex expr
// }

if field.Tag.Get(rangeTag) != "" {
// translate rage to an array
}
// if field.Tag.Get(rangeTag) != "" {
// translate rage to an array
// }

// comparison operator choices
if reflect.TypeOf(field) == reflect.TypeOf(ComparisonOperator{}) {
// // comparison operator choices
// if reflect.TypeOf(field) == reflect.TypeOf(ComparisonOperator{}) {

}
// }

// list clusters on which the metrics are defined
if reflect.TypeOf(field) == reflect.TypeOf(corev1.Cluster{}) {
// // list clusters on which the metrics are defined
// if reflect.TypeOf(field) == reflect.TypeOf(corev1.Cluster{}) {

}
// }

// list multiples of time.Duration
if reflect.TypeOf(field) == reflect.TypeOf(time.Duration(0)) {
// // list multiples of time.Duration
// if reflect.TypeOf(field) == reflect.TypeOf(time.Duration(0)) {

}
// }
}
return values, nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/alerting/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func IsNil(p *Provider) bool {
}

func DoCreate(
p Provider,
ctx context.Context,
p Provider,
req *alertingv1.AlertCondition,
) (*corev1.Reference, error) {
alertingMutex.Lock()
Expand All @@ -42,8 +42,8 @@ func DoCreate(
}

func DoDelete(
p Provider,
ctx context.Context,
p Provider,
req *corev1.Reference,
) (*emptypb.Empty, error) {
alertingMutex.Lock()
Expand All @@ -52,8 +52,8 @@ func DoDelete(
}

func DoTrigger(
p Provider,
ctx context.Context,
p Provider,
req *alertingv1.TriggerAlertsRequest,
) (*alertingv1.TriggerAlertsResponse, error) {
alertingMutex.Lock()
Expand Down
6 changes: 3 additions & 3 deletions pkg/alerting/routing/api_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ func (r *Receiver) Equal(other *Receiver) (bool, string) {
return receiversAreEqual(r, other)
}

func (c *Receiver) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (r *Receiver) UnmarshalYAML(unmarshal func(interface{}) error) error {
type plain Receiver
if err := unmarshal((*plain)(c)); err != nil {
if err := unmarshal((*plain)(r)); err != nil {
return err
}
if c.Name == "" {
if r.Name == "" {
return fmt.Errorf("missing name in receiver")
}
return nil
Expand Down
43 changes: 21 additions & 22 deletions pkg/alerting/routing/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,23 @@ func (r *RoutingTree) Equal(input any) (equal bool, reason string) {
selfReceiverIndex := r.indexOpniReceivers()
otherReceiverIndex := other.indexOpniReceivers()
for id, r1 := range selfReceiverIndex {
if r2, ok := otherReceiverIndex[id]; !ok {
r2, ok := otherReceiverIndex[id]
if !ok {
return false, fmt.Sprintf("configurations do not have matching receiver : %s", id)
} else {
if equal, reason := r1.Equal(r2); !equal {
return false, fmt.Sprintf("configurations do not have equal receivers '%s' : %s", id, reason)
}
}
if equal, reason := r1.Equal(r2); !equal {
return false, fmt.Sprintf("configurations do not have equal receivers '%s' : %s", id, reason)
}
}
selfRoutingIndex := r.indexOpniRoutes()
otherRoutingIndex := other.indexOpniRoutes()
for id, r1 := range selfRoutingIndex {
if r2, ok := otherRoutingIndex[id]; !ok {
r2, ok := otherRoutingIndex[id]
if !ok {
return false, fmt.Sprintf("configurations do not have matching route : %s", id)
} else {
if equal, reason := routesAreEqual(r1, r2); !equal {
return false, fmt.Sprintf("configurations do not have equal route '%s' : %s", id, reason)
}
}
if equal, reason := routesAreEqual(r1, r2); !equal {
return false, fmt.Sprintf("configurations do not have equal route '%s' : %s", id, reason)
}
}
return true, ""
Expand Down Expand Up @@ -294,23 +294,23 @@ func (o *OpniInternalRouting) Add(
}

func (o *OpniInternalRouting) GetFromCondition(conditionId string) (map[string]*OpniRoutingMetadata, error) {
if res, ok := o.Content[conditionId]; !ok {
res, ok := o.Content[conditionId]
if !ok {
return nil, shared.WithNotFoundError("existing condition id that is expected to exist not found in internal routing ids")
} else {
return res, nil
}
return res, nil
}

func (o *OpniInternalRouting) Get(conditionId, endpointId string) (*OpniRoutingMetadata, error) {
if condition, ok := o.Content[conditionId]; !ok {
condition, ok := o.Content[conditionId]
if !ok {
return nil, shared.WithNotFoundError("existing condition id that is expected to exist not found in internal routing ids")
} else {
if metadata, ok := condition[endpointId]; !ok {
return nil, shared.WithNotFoundError("existing condition/endpoint id pair that is expected to exist not found in internal routing ids")
} else {
return metadata, nil
}
}
metadata, ok := condition[endpointId]
if !ok {
return nil, shared.WithNotFoundError("existing condition/endpoint id pair that is expected to exist not found in internal routing ids")
}
return metadata, nil
}

func (o *OpniInternalRouting) UpdateEndpoint(conditionId, notificationId string, metadata OpniRoutingMetadata) error {
Expand Down Expand Up @@ -347,8 +347,7 @@ func (o *OpniInternalRouting) RemoveEndpoint(conditionId string, endpointId stri
func (o *OpniInternalRouting) RemoveCondition(conditionId string) error {
if _, ok := o.Content[conditionId]; !ok {
return shared.WithNotFoundError("existing condition id that is expected to exist not found in internal routing ids")
} else {
delete(o.Content, conditionId)
}
delete(o.Content, conditionId)
return nil
}
4 changes: 2 additions & 2 deletions pkg/alerting/routing/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (r *RoutingTree) UpdateIndividualEndpointNode(
}
for _, metadata := range internalRouting.Content[toTraverseItem.conditionId] {
if metadata.EndpointType == toTraverseItem.endpointType && *metadata.Position > toTraverseItem.position {
*metadata.Position -= 1
*metadata.Position--
}
}
// add with correct config while updating internal routing
Expand Down Expand Up @@ -269,7 +269,7 @@ func (r *RoutingTree) DeleteIndividualEndpointNode(
}
for _, metadata := range internalRouting.Content[toTraverseItem.conditionId] {
if metadata.EndpointType == toTraverseItem.endpointType && *metadata.Position > toTraverseItem.position {
*metadata.Position -= 1
*metadata.Position--
}
}
// add with correct config while updating internal routing
Expand Down
2 changes: 1 addition & 1 deletion pkg/alerting/routing/pagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c *PagerdutyConfig) Default() OpniConfig {
}
}

func (p *PagerdutyConfig) InternalId() string {
func (c *PagerdutyConfig) InternalId() string {
return "pagerduty"
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/capability/v1/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ func (d *Duration) UnmarshalJSON(b []byte) error {
}
switch value := value.(type) {
case string:
if parsed, err := time.ParseDuration(value); err != nil {
parsed, err := time.ParseDuration(value)
if err != nil {
return err
} else {
*d = Duration(parsed)
}
*d = Duration(parsed)
case float64:
*d = Duration(time.Duration(value))
default:
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/control/v1/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func (m *PluginManifest) Sort() {
})
}

func (m *PluginArchive) Sort() {
slices.SortFunc(m.Items, func(a, b *PluginArchiveEntry) bool {
func (a *PluginArchive) Sort() {
slices.SortFunc(a.Items, func(a, b *PluginArchiveEntry) bool {
return a.GetMetadata().GetModule() < b.GetMetadata().GetModule()
})
}
Expand All @@ -58,8 +58,8 @@ func (a *PluginArchive) ToManifest() *PluginManifest {
return manifest
}

func (a *PatchList) Sort() {
slices.SortFunc(a.Items, func(a, b *PatchSpec) bool {
func (l *PatchList) Sort() {
slices.SortFunc(l.Items, func(a, b *PatchSpec) bool {
if a.GetOp() != b.GetOp() {
return a.GetOp() < b.GetOp()
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/auth/openid/openid.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (m *OpenidMiddleware) Handle(c *gin.Context) {

func (m *OpenidMiddleware) tryConfigureKeyRefresher(ctx context.Context) {
lg := m.logger
result, err, _ := sfGroup.Do(m.configId, func() (interface{}, error) {
result, _, _ := sfGroup.Do(m.configId, func() (interface{}, error) {
p := backoff.Exponential(
backoff.WithMaxRetries(0),
backoff.WithMinInterval(50*time.Millisecond),
Expand All @@ -163,6 +163,7 @@ func (m *OpenidMiddleware) tryConfigureKeyRefresher(ctx context.Context) {
}
panic("unreachable")
})

wellKnownCfg := result.(*WellKnownConfiguration)
lg.With(
"issuer", wellKnownCfg.Issuer,
Expand Down Expand Up @@ -197,6 +198,7 @@ func (m *OpenidMiddleware) tryConfigureKeyRefresher(ctx context.Context) {
m.keyRefresher.Configure(wellKnownCfg.JwksUri,
jwk.WithHTTPClient(httpClient),
)
var err error
m.cache, err = NewUserInfoCache(m.conf, m.logger, WithHTTPClient(httpClient))
if err != nil {
lg.With(
Expand Down
Loading

0 comments on commit 6286c29

Please sign in to comment.