Skip to content

Commit 27cf7c5

Browse files
oleksandr-codefreshppapapetrou76
authored andcommitted
chore: sync all codefresh code changes into v3.0.2 without event-reporter related changes
Signed-off-by: oleksandr-codefresh <oleksandr.saulyak@octopus.com>
1 parent b969c2d commit 27cf7c5

File tree

10 files changed

+52
-30
lines changed

10 files changed

+52
-30
lines changed

acr_controller/application/client.go

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

2829
func NewHTTPApplicationClient(token string, address string, rootpath string) ApplicationClient {
@@ -46,13 +47,14 @@ func NewHTTPApplicationClient(token string, address string, rootpath string) App
4647
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
4748
},
4849
},
49-
baseURL: address,
50-
token: token,
50+
baseURL: address,
51+
token: token,
52+
rootpath: rootpath,
5153
}
5254
}
5355

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

acr_controller/controller/controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ 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"
1618
)
1719

1820
var watchAPIBufferSize = 1000

acr_controller/server.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ package acr_controller
22

33
import (
44
"context"
5+
"crypto/tls"
56
"fmt"
67
"net"
78
"net/http"
89
"time"
910

11+
applisters "github.com/argoproj/argo-cd/v3/pkg/client/listers/application/v1alpha1"
12+
settings_util "github.com/argoproj/argo-cd/v3/util/settings"
1013
"github.com/redis/go-redis/v9"
1114
log "github.com/sirupsen/logrus"
1215
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -33,11 +36,15 @@ var backoff = wait.Backoff{
3336
type ACRServer struct {
3437
ACRServerOpts
3538

39+
settings *settings_util.ArgoCDSettings
40+
log *log.Entry
3641
appInformer cache.SharedIndexInformer
42+
appLister applisters.ApplicationLister
3743
applicationClientset appclientset.Interface
3844

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

4350
type ACRServerSet struct{}
@@ -156,6 +163,10 @@ func (a *ACRServer) Listen() (*Listeners, error) {
156163
// golang/protobuf).
157164
func (a *ACRServer) Run(ctx context.Context, lns *Listeners) {
158165
httpS := a.newHTTPServer(ctx, a.ListenPort)
166+
tlsConfig := tls.Config{}
167+
tlsConfig.GetCertificate = func(_ *tls.ClientHelloInfo) (*tls.Certificate, error) {
168+
return a.settings.Certificate, nil
169+
}
159170
go func() { a.checkServeErr("httpS", httpS.Serve(lns.Main)) }()
160171
go a.RunController(ctx)
161172

@@ -176,10 +187,13 @@ func NewApplicationChangeRevisionServer(_ context.Context, opts ACRServerOpts) *
176187
appFactory := appinformer.NewSharedInformerFactoryWithOptions(opts.AppClientset, 0, appinformer.WithNamespace(appInformerNs), appinformer.WithTweakListOptions(func(_ *metav1.ListOptions) {}))
177188

178189
appInformer := appFactory.Argoproj().V1alpha1().Applications().Informer()
190+
appLister := appFactory.Argoproj().V1alpha1().Applications().Lister()
179191

180192
server := &ACRServer{
181193
ACRServerOpts: opts,
194+
log: log.NewEntry(log.StandardLogger()),
182195
appInformer: appInformer,
196+
appLister: appLister,
183197
applicationClientset: opts.AppClientset,
184198
}
185199

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.Empty(t, current)
233-
assert.Empty(t, previous)
232+
assert.Equal(t, "", current)
233+
assert.Equal(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.Empty(t, previous)
240+
assert.Equal(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.Empty(t, previous)
247+
assert.Equal(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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,13 @@ func NewCommand() *cobra.Command {
128128
lns, err := changeRevisionServer.Listen()
129129
errors.CheckError(err)
130130
for {
131+
var closer func()
131132
ctx, cancel := context.WithCancel(ctx)
132133
changeRevisionServer.Run(ctx, lns)
133134
cancel()
135+
if closer != nil {
136+
closer()
137+
}
134138
}
135139
},
136140
}

server/application/application_rollout_rollback.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,22 @@ func (s *Server) getRsOfSpecificRevision(ctx context.Context, config *rest.Confi
7878
if err != nil {
7979
return nil, fmt.Errorf("error getting resource: %w", err)
8080
}
81-
v := resource.GetRevision(rsliveObj)
82-
switch toRevision {
83-
case 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
81+
if v := resource.GetRevision(rsliveObj); err == nil {
82+
if toRevision == 0 {
83+
if latestRevision < v {
84+
// newest one we've seen so far
85+
previousRevision = latestRevision
86+
previousReplicaSet = latestReplicaSet
87+
latestRevision = v
88+
latestReplicaSet = rsliveObj
89+
} else if previousRevision < v {
90+
// second newest one we've seen so far
91+
previousRevision = v
92+
previousReplicaSet = rsliveObj
93+
}
94+
} else if toRevision == v {
95+
return rsliveObj, nil
9496
}
95-
case v:
96-
return rsliveObj, nil
9797
}
9898
}
9999

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

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

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.Name, err.Error())
38+
errMsg := fmt.Sprintf("application destination spec for %s is invalid: %s", app.ObjectMeta.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.Name, argo.FormatAppConditions(conditions))
56+
errMsg := fmt.Sprintf("application spec for %s is invalid: %s", app.ObjectMeta.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-
utilio "github.com/argoproj/argo-cd/v3/util/io"
15+
ioutil "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 utilio.Close(closer)
44+
defer ioutil.Close(closer)
4545

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

util/kustomize/repospec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func parseGitURL(n string) (
3434
index := strings.Index(n, gitSuffix)
3535
orgRepo = n[0:index]
3636
n = n[index+len(gitSuffix):]
37-
if n != "" && n[0] == '/' {
37+
if len(n) > 0 && n[0] == '/' {
3838
n = n[1:]
3939
}
4040
path, gitRef = peelQuery(n)

util/kustomize/repospec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var hostNamesRawAndNormalized = [][]string{
4343
}
4444

4545
func makeURL(hostFmt, orgRepo, path, href string) string {
46-
if path != "" {
46+
if len(path) > 0 {
4747
orgRepo = filepath.Join(orgRepo, path)
4848
}
4949
url := hostFmt + orgRepo

0 commit comments

Comments
 (0)