Skip to content

Commit

Permalink
fix(server): handle PATCH in http/s server (#2677) (#14530) (#14732)
Browse files Browse the repository at this point in the history
Signed-off-by: mmerrill3 <[email protected]>
Co-authored-by: Michael Merrill <[email protected]>
  • Loading branch information
gcp-cherry-pick-bot[bot] and mmerrill3 authored Jul 27, 2023
1 parent 316be4e commit 84e2f77
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
6 changes: 3 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,12 @@ func (a *ArgoCDServer) Run(ctx context.Context, listeners *Listeners) {
var httpL net.Listener
var httpsL net.Listener
if !a.useTLS() {
httpL = tcpm.Match(cmux.HTTP1Fast())
httpL = tcpm.Match(cmux.HTTP1Fast("PATCH"))
grpcL = tcpm.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"))

} else {
// We first match on HTTP 1.1 methods.
httpL = tcpm.Match(cmux.HTTP1Fast())
httpL = tcpm.Match(cmux.HTTP1Fast("PATCH"))

// If not matched, we assume that its TLS.
tlsl := tcpm.Match(cmux.Any())
Expand All @@ -532,7 +532,7 @@ func (a *ArgoCDServer) Run(ctx context.Context, listeners *Listeners) {

// Now, we build another mux recursively to match HTTPS and gRPC.
tlsm = cmux.New(tlsl)
httpsL = tlsm.Match(cmux.HTTP1Fast())
httpsL = tlsm.Match(cmux.HTTP1Fast("PATCH"))
grpcL = tlsm.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"))
}

Expand Down
18 changes: 18 additions & 0 deletions test/e2e/app_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,24 @@ func TestDeleteAppResource(t *testing.T) {
Expect(HealthIs(health.HealthStatusMissing))
}

// Fix for issue #2677, support PATCH in HTTP service
func TestPatchHttp(t *testing.T) {
ctx := Given(t)

ctx.
Path(guestbookPath).
When().
CreateApp().
Sync().
PatchAppHttp(`{"metadata": {"labels": { "test": "patch" }, "annotations": { "test": "patch" }}}`).
Then().
And(func(app *Application) {
assert.Equal(t, "patch", app.Labels["test"])
assert.Equal(t, "patch", app.Annotations["test"])
})

}

// demonstrate that we cannot use a standard sync when an immutable field is changed, we must use "force"
func TestImmutableChange(t *testing.T) {
SkipOnEnv(t, "OPENSHIFT")
Expand Down
24 changes: 24 additions & 0 deletions test/e2e/fixture/app/actions.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package app

import (
"encoding/json"
"fmt"
"os"

log "github.com/sirupsen/logrus"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

client "github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
. "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture"
"github.com/argoproj/argo-cd/v2/util/errors"
Expand Down Expand Up @@ -289,6 +291,28 @@ func (a *Actions) PatchApp(patch string) *Actions {
return a
}

func (a *Actions) PatchAppHttp(patch string) *Actions {
a.context.t.Helper()
var application Application
var patchType = "merge"
var appName = a.context.AppQualifiedName()
var appNamespace = a.context.AppNamespace()
patchRequest := &client.ApplicationPatchRequest{
Name: &appName,
PatchType: &patchType,
Patch: &patch,
AppNamespace: &appNamespace,
}
jsonBytes, err := json.MarshalIndent(patchRequest, "", " ")
errors.CheckError(err)
err = fixture.DoHttpJsonRequest("PATCH",
fmt.Sprintf("/api/v1/applications/%v", appName),
&application,
jsonBytes...)
errors.CheckError(err)
return a
}

func (a *Actions) AppSet(flags ...string) *Actions {
a.context.t.Helper()
args := []string{"app", "set", a.context.AppQualifiedName()}
Expand Down

0 comments on commit 84e2f77

Please sign in to comment.