Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): handle PATCH in http/s server (#2677) #14530

Merged
merged 4 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,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 @@ -480,7 +480,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 @@ -476,6 +476,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 @@ -295,6 +297,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
Loading