Skip to content

Commit f4808a5

Browse files
committed
address new linter issues
Signed-off-by: Patroklos Papapetrou <ppapapetrou76@gmail.com>
1 parent 901fe22 commit f4808a5

File tree

12 files changed

+41
-79
lines changed

12 files changed

+41
-79
lines changed

acr_controller/application/client.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ type httpApplicationClient struct {
2323
httpClient *http.Client
2424
baseURL string
2525
token string
26-
rootpath string
2726
}
2827

2928
func NewHTTPApplicationClient(token string, address string, rootpath string) ApplicationClient {
@@ -47,14 +46,13 @@ func NewHTTPApplicationClient(token string, address string, rootpath string) App
4746
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
4847
},
4948
},
50-
baseURL: address,
51-
token: token,
52-
rootpath: rootpath,
49+
baseURL: address,
50+
token: token,
5351
}
5452
}
5553

5654
func (c *httpApplicationClient) execute(ctx context.Context, url string, result any) error {
57-
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
55+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody)
5856
if err != nil {
5957
return err
6058
}

acr_controller/controller/broadcaster.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ func (b *broadcasterHandler) notify(event *appv1.ApplicationWatchEvent) {
5757
if s.matches(event) {
5858
select {
5959
case s.ch <- event:
60-
{
61-
// log.Infof("adding application '%s' to channel", event.Application.Name)
62-
}
60+
log.Infof("adding application '%s' to channel", event.Application.Name)
6361
default:
6462
// drop event if cannot send right away
6563
log.WithField("application", event.Application.Name).Warn("unable to send event notification")

acr_controller/controller/controller.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
appclientset "github.com/argoproj/argo-cd/v3/pkg/client/clientset/versioned"
1414

1515
appv1 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
16-
applisters "github.com/argoproj/argo-cd/v3/pkg/client/listers/application/v1alpha1"
17-
servercache "github.com/argoproj/argo-cd/v3/server/cache"
1816
)
1917

2018
var watchAPIBufferSize = 1000
@@ -24,27 +22,19 @@ type ACRController interface {
2422
}
2523

2624
type applicationChangeRevisionController struct {
27-
appBroadcaster Broadcaster
28-
cache *servercache.Cache
29-
appLister applisters.ApplicationLister
30-
applicationServiceClient appclient.ApplicationClient
31-
acrService service.ACRService
32-
applicationClientset appclientset.Interface
25+
appBroadcaster Broadcaster
26+
acrService service.ACRService
3327
}
3428

35-
func NewApplicationChangeRevisionController(appInformer cache.SharedIndexInformer, cache *servercache.Cache, applicationServiceClient appclient.ApplicationClient, appLister applisters.ApplicationLister, applicationClientset appclientset.Interface) ACRController {
29+
func NewApplicationChangeRevisionController(appInformer cache.SharedIndexInformer, applicationServiceClient appclient.ApplicationClient, applicationClientset appclientset.Interface) ACRController {
3630
appBroadcaster := NewBroadcaster()
3731
_, err := appInformer.AddEventHandler(appBroadcaster)
3832
if err != nil {
3933
log.Error(err)
4034
}
4135
return &applicationChangeRevisionController{
42-
appBroadcaster: appBroadcaster,
43-
cache: cache,
44-
applicationServiceClient: applicationServiceClient,
45-
appLister: appLister,
46-
applicationClientset: applicationClientset,
47-
acrService: service.NewACRService(applicationClientset, applicationServiceClient),
36+
appBroadcaster: appBroadcaster,
37+
acrService: service.NewACRService(applicationClientset, applicationServiceClient),
4838
}
4939
}
5040

acr_controller/server.go

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package acr_controller
22

33
import (
44
"context"
5-
"crypto/tls"
65
"fmt"
76
"net"
87
"net/http"
@@ -20,10 +19,8 @@ import (
2019

2120
appclientset "github.com/argoproj/argo-cd/v3/pkg/client/clientset/versioned"
2221
appinformer "github.com/argoproj/argo-cd/v3/pkg/client/informers/externalversions"
23-
applisters "github.com/argoproj/argo-cd/v3/pkg/client/listers/application/v1alpha1"
2422
servercache "github.com/argoproj/argo-cd/v3/server/cache"
2523
"github.com/argoproj/argo-cd/v3/util/healthz"
26-
settings_util "github.com/argoproj/argo-cd/v3/util/settings"
2724
)
2825

2926
var backoff = wait.Backoff{
@@ -36,15 +33,11 @@ var backoff = wait.Backoff{
3633
type ACRServer struct {
3734
ACRServerOpts
3835

39-
settings *settings_util.ArgoCDSettings
40-
log *log.Entry
4136
appInformer cache.SharedIndexInformer
42-
appLister applisters.ApplicationLister
4337
applicationClientset appclientset.Interface
4438

4539
// stopCh is the channel which when closed, will shutdown the Event Reporter server
46-
stopCh chan struct{}
47-
serviceSet *ACRServerSet
40+
stopCh chan struct{}
4841
}
4942

5043
type ACRServerSet struct{}
@@ -100,12 +93,10 @@ func (a *ACRServer) healthCheck(_ *http.Request) error {
10093
// Init starts informers used by the API server
10194
func (a *ACRServer) Init(ctx context.Context) {
10295
go a.appInformer.Run(ctx.Done())
103-
svcSet := newApplicationChangeRevisionServiceSet()
104-
a.serviceSet = svcSet
10596
}
10697

10798
func (a *ACRServer) RunController(ctx context.Context) {
108-
controller := acr_controller.NewApplicationChangeRevisionController(a.appInformer, a.Cache, a.ApplicationServiceClient, a.appLister, a.applicationClientset)
99+
controller := acr_controller.NewApplicationChangeRevisionController(a.appInformer, a.ApplicationServiceClient, a.applicationClientset)
109100
go controller.Run(ctx)
110101
}
111102

@@ -164,10 +155,6 @@ func (a *ACRServer) Listen() (*Listeners, error) {
164155
// golang/protobuf).
165156
func (a *ACRServer) Run(ctx context.Context, lns *Listeners) {
166157
httpS := a.newHTTPServer(ctx, a.ListenPort)
167-
tlsConfig := tls.Config{}
168-
tlsConfig.GetCertificate = func(_ *tls.ClientHelloInfo) (*tls.Certificate, error) {
169-
return a.settings.Certificate, nil
170-
}
171158
go func() { a.checkServeErr("httpS", httpS.Serve(lns.Main)) }()
172159
go a.RunController(ctx)
173160

@@ -179,7 +166,7 @@ func (a *ACRServer) Run(ctx context.Context, lns *Listeners) {
179166
<-a.stopCh
180167
}
181168

182-
// NewServer returns a new instance of the Event Reporter server
169+
// NewApplicationChangeRevisionServer returns a new instance of the Event Reporter server
183170
func NewApplicationChangeRevisionServer(_ context.Context, opts ACRServerOpts) *ACRServer {
184171
appInformerNs := opts.Namespace
185172
if len(opts.ApplicationNamespaces) > 0 {
@@ -188,19 +175,12 @@ func NewApplicationChangeRevisionServer(_ context.Context, opts ACRServerOpts) *
188175
appFactory := appinformer.NewSharedInformerFactoryWithOptions(opts.AppClientset, 0, appinformer.WithNamespace(appInformerNs), appinformer.WithTweakListOptions(func(_ *metav1.ListOptions) {}))
189176

190177
appInformer := appFactory.Argoproj().V1alpha1().Applications().Informer()
191-
appLister := appFactory.Argoproj().V1alpha1().Applications().Lister()
192178

193179
server := &ACRServer{
194180
ACRServerOpts: opts,
195-
log: log.NewEntry(log.StandardLogger()),
196181
appInformer: appInformer,
197-
appLister: appLister,
198182
applicationClientset: opts.AppClientset,
199183
}
200184

201185
return server
202186
}
203-
204-
func newApplicationChangeRevisionServiceSet() *ACRServerSet {
205-
return &ACRServerSet{}
206-
}

acr_controller/service/acr_service_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,22 +229,22 @@ func Test_getRevisions(r *testing.T) {
229229
r.Run("history list is empty", func(t *testing.T) {
230230
acrService := newTestACRService(&mocks.ApplicationClient{})
231231
current, previous := acrService.getRevisions(r.Context(), createTestApp(fakeApp))
232-
assert.Equal(t, "", current)
233-
assert.Equal(t, "", previous)
232+
assert.Empty(t, current)
233+
assert.Empty(t, previous)
234234
})
235235

236236
r.Run("history list is empty, but operation happens right now", func(t *testing.T) {
237237
acrService := newTestACRService(&mocks.ApplicationClient{})
238238
current, previous := acrService.getRevisions(r.Context(), createTestApp(fakeAppWithOperation))
239239
assert.Equal(t, "c732f4d2ef24c7eeb900e9211ff98f90bb646505", current)
240-
assert.Equal(t, "", previous)
240+
assert.Empty(t, previous)
241241
})
242242

243243
r.Run("history list contains only one element, also sync result is here", func(t *testing.T) {
244244
acrService := newTestACRService(&mocks.ApplicationClient{})
245245
current, previous := acrService.getRevisions(r.Context(), createTestApp(syncedAppWithSingleHistory))
246246
assert.Equal(t, "c732f4d2ef24c7eeb900e9211ff98f90bb646505", current)
247-
assert.Equal(t, "", previous)
247+
assert.Empty(t, previous)
248248
})
249249

250250
r.Run("application is synced", func(t *testing.T) {

cmd/application-change-revision-controller/commands/application_change_revision_controller.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,9 @@ func NewCommand() *cobra.Command {
126126
lns, err := changeRevisionServer.Listen()
127127
errors.CheckError(err)
128128
for {
129-
var closer func()
130129
ctx, cancel := context.WithCancel(ctx)
131130
changeRevisionServer.Run(ctx, lns)
132131
cancel()
133-
if closer != nil {
134-
closer()
135-
}
136132
}
137133
},
138134
}

server/application/application_rollout_rollback.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,22 @@ func (s *Server) getRsOfSpecificRevision(ctx context.Context, config *rest.Confi
7979
return nil, fmt.Errorf("error getting resource: %w", err)
8080
}
8181

82-
if v := resource.GetRevision(rsliveObj); err == nil {
83-
if toRevision == 0 {
84-
if latestRevision < v {
85-
// newest one we've seen so far
86-
previousRevision = latestRevision
87-
previousReplicaSet = latestReplicaSet
88-
latestRevision = v
89-
latestReplicaSet = rsliveObj
90-
} else if previousRevision < v {
91-
// second newest one we've seen so far
92-
previousRevision = v
93-
previousReplicaSet = rsliveObj
94-
}
95-
} else if toRevision == v {
96-
return rsliveObj, nil
82+
v := resource.GetRevision(rsliveObj)
83+
switch toRevision {
84+
case 0:
85+
if latestRevision < v {
86+
// newest one we've seen so far
87+
previousRevision = latestRevision
88+
previousReplicaSet = latestReplicaSet
89+
latestRevision = v
90+
latestReplicaSet = rsliveObj
91+
} else if previousRevision < v {
92+
// second newest one we've seen so far
93+
previousRevision = v
94+
previousReplicaSet = rsliveObj
9795
}
96+
case v:
97+
return rsliveObj, nil
9898
}
9999
}
100100

@@ -139,7 +139,7 @@ func (s *Server) getReplicaSetForRolloutRollack(ctx context.Context, config *res
139139
rolloutGVK := getRolloutGVK()
140140

141141
foundRolloutNode := tree.FindNode(rolloutGVK.Group, rolloutGVK.Kind, q.GetRolloutNamespace(), q.GetRolloutName())
142-
if foundRolloutNode == nil || foundRolloutNode.ResourceRef.UID == "" {
142+
if foundRolloutNode == nil || foundRolloutNode.UID == "" {
143143
return nil, status.Errorf(codes.InvalidArgument, "%s %s %s not found as part of application %s", rolloutGVK.Kind, rolloutGVK.Group, q.GetRolloutName(), q.GetName())
144144
}
145145

server/application/application_validate_src_and_dest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (s *Server) ValidateSrcAndDst(ctx context.Context, requset *application.App
3535

3636
if err := validateDestination(ctx, &app.Spec.Destination, s.db); err != nil {
3737
entity := destinationEntity
38-
errMsg := fmt.Sprintf("application destination spec for %s is invalid: %s", app.ObjectMeta.Name, err.Error())
38+
errMsg := fmt.Sprintf("application destination spec for %s is invalid: %s", app.Name, err.Error())
3939
return &application.ApplicationValidateResponse{
4040
Error: &errMsg,
4141
Entity: &entity,
@@ -53,7 +53,7 @@ func (s *Server) ValidateSrcAndDst(ctx context.Context, requset *application.App
5353
}
5454
if len(conditions) > 0 {
5555
entity := sourceEntity
56-
errMsg := fmt.Sprintf("application spec for %s is invalid: %s", app.ObjectMeta.Name, argo.FormatAppConditions(conditions))
56+
errMsg := fmt.Sprintf("application spec for %s is invalid: %s", app.Name, argo.FormatAppConditions(conditions))
5757
return &application.ApplicationValidateResponse{
5858
Error: &errMsg,
5959
Entity: &entity,

server/application/cf_application.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
appv1 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
1313
"github.com/argoproj/argo-cd/v3/reposerver/apiclient"
1414
"github.com/argoproj/argo-cd/v3/util/app/path"
15-
ioutil "github.com/argoproj/argo-cd/v3/util/io"
15+
utilio "github.com/argoproj/argo-cd/v3/util/io"
1616
)
1717

1818
const (
@@ -41,7 +41,7 @@ func (s *Server) GetChangeRevision(ctx context.Context, in *application.ChangeRe
4141
if err != nil {
4242
return nil, fmt.Errorf("error creating repo server client: %w", err)
4343
}
44-
defer ioutil.Close(closer)
44+
defer utilio.Close(closer)
4545

4646
response, err := client.GetChangeRevision(ctx, &apiclient.ChangeRevisionRequest{
4747
AppName: in.GetAppName(),

util/exec/exec_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ func TestRunInDir(t *testing.T) {
203203
}
204204

205205
func TestRedact(t *testing.T) {
206-
assert.Equal(t, "", Redact(nil)(""))
207-
assert.Equal(t, "", Redact([]string{})(""))
208-
assert.Equal(t, "", Redact([]string{"foo"})(""))
206+
assert.Empty(t, Redact(nil)(""))
207+
assert.Empty(t, Redact([]string{})(""))
208+
assert.Empty(t, Redact([]string{"foo"})(""))
209209
assert.Equal(t, "foo", Redact([]string{})("foo"))
210210
assert.Equal(t, "******", Redact([]string{"foo"})("foo"))
211211
assert.Equal(t, "****** ******", Redact([]string{"foo", "bar"})("foo bar"))

0 commit comments

Comments
 (0)