Skip to content

Commit 1cbd28c

Browse files
fix(server): make parameterized resource actions backwards-compatible (cherry-pick #23695) (#23709)
Signed-off-by: Michael Crenshaw <[email protected]> Co-authored-by: Michael Crenshaw <[email protected]>
1 parent 6fe5ec7 commit 1cbd28c

File tree

12 files changed

+1288
-299
lines changed

12 files changed

+1288
-299
lines changed

assets/swagger.json

Lines changed: 78 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/argocd/commands/app_actions.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ import (
88
"strconv"
99
"text/tabwriter"
1010

11-
"github.com/argoproj/argo-cd/v3/util/templates"
12-
13-
"github.com/argoproj/argo-cd/v3/cmd/util"
14-
1511
log "github.com/sirupsen/logrus"
1612
"github.com/spf13/cobra"
13+
"google.golang.org/grpc/codes"
1714
"k8s.io/utils/ptr"
1815
"sigs.k8s.io/yaml"
1916

2017
"github.com/argoproj/argo-cd/v3/cmd/argocd/commands/headless"
18+
"github.com/argoproj/argo-cd/v3/cmd/util"
2119
argocdclient "github.com/argoproj/argo-cd/v3/pkg/apiclient"
2220
applicationpkg "github.com/argoproj/argo-cd/v3/pkg/apiclient/application"
2321
"github.com/argoproj/argo-cd/v3/pkg/apis/application"
2422
"github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
2523
"github.com/argoproj/argo-cd/v3/util/argo"
2624
"github.com/argoproj/argo-cd/v3/util/errors"
25+
"github.com/argoproj/argo-cd/v3/util/grpc"
2726
utilio "github.com/argoproj/argo-cd/v3/util/io"
27+
"github.com/argoproj/argo-cd/v3/util/templates"
2828
)
2929

3030
type DisplayedAction struct {
@@ -192,7 +192,26 @@ func NewApplicationResourceActionsRunCommand(clientOpts *argocdclient.ClientOpti
192192
obj := filteredObjects[i]
193193
gvk := obj.GroupVersionKind()
194194
objResourceName := obj.GetName()
195-
_, err := appIf.RunResourceAction(ctx, &applicationpkg.ResourceActionRunRequest{
195+
_, err := appIf.RunResourceActionV2(ctx, &applicationpkg.ResourceActionRunRequestV2{
196+
Name: &appName,
197+
AppNamespace: &appNs,
198+
Namespace: ptr.To(obj.GetNamespace()),
199+
ResourceName: ptr.To(objResourceName),
200+
Group: ptr.To(gvk.Group),
201+
Kind: ptr.To(gvk.Kind),
202+
Version: ptr.To(gvk.GroupVersion().Version),
203+
Action: ptr.To(actionName),
204+
// TODO: add support for parameters
205+
})
206+
if err == nil {
207+
continue
208+
}
209+
if grpc.UnwrapGRPCStatus(err).Code() != codes.Unimplemented {
210+
errors.CheckError(err)
211+
}
212+
fmt.Println("RunResourceActionV2 is not supported by the server, falling back to RunResourceAction.")
213+
//nolint:staticcheck // RunResourceAction is deprecated, but we still need to support it for backward compatibility.
214+
_, err = appIf.RunResourceAction(ctx, &applicationpkg.ResourceActionRunRequest{
196215
Name: &appName,
197216
AppNamespace: &appNs,
198217
Namespace: ptr.To(obj.GetNamespace()),

cmd/argocd/commands/app_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,10 +2228,15 @@ func (c *fakeAppServiceClient) ListResourceActions(_ context.Context, _ *applica
22282228
return nil, nil
22292229
}
22302230

2231+
// nolint:staticcheck // ResourceActionRunRequest is deprecated, but we still need to implement it to satisfy the server interface.
22312232
func (c *fakeAppServiceClient) RunResourceAction(_ context.Context, _ *applicationpkg.ResourceActionRunRequest, _ ...grpc.CallOption) (*applicationpkg.ApplicationResponse, error) {
22322233
return nil, nil
22332234
}
22342235

2236+
func (c *fakeAppServiceClient) RunResourceActionV2(_ context.Context, _ *applicationpkg.ResourceActionRunRequestV2, _ ...grpc.CallOption) (*applicationpkg.ApplicationResponse, error) {
2237+
return nil, nil
2238+
}
2239+
22352240
func (c *fakeAppServiceClient) DeleteResource(_ context.Context, _ *applicationpkg.ApplicationResourceDeleteRequest, _ ...grpc.CallOption) (*applicationpkg.ApplicationResponse, error) {
22362241
return nil, nil
22372242
}

docs/operator-manual/upgrading/3.0-3.1.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,28 @@ The `--staticassets` directory in the API server (`/app/shared` by default) is n
2020
symlinks. This is to help protect against symlink attacks. If you have any symlinks in your `--staticassets` directory
2121
to a location outside the directory, they will return a 500 error starting with 3.1.
2222

23+
## v1 Actions API Deprecated
24+
25+
The `/api/v1/applications/{name}/resource/actions` endpoint is deprecated in favor of `/api/v1/applications/{name}/resource/actions/v2`.
26+
27+
This endpoint allows API users to run a custom resource action on a specific resource in an application.
28+
29+
The old endpoint accepted various parameters as query parameters. The POST body was the action name.
30+
31+
The new endpoint accepts all parameters as part of the POST body as a JSON object. The new endpoint also supports a new
32+
`resourceActionParameters` field to parameterize action runs.
33+
34+
The old endpoint will be removed in a future release, so users should migrate to the new endpoint as soon as possible.
35+
API clients will just need to change the endpoint URL and switch query string parameters to a JSON body.
36+
37+
If the old endpoint is used, the API will log a warning message:
38+
39+
> RunResourceAction was called. RunResourceAction is deprecated and will be removed in a future release. Use RunResourceActionV2 instead.
40+
41+
The CLI will fall back to the old endpoint if the new one is not available. If it falls back, it will log a warning message:
42+
43+
> RunResourceActionV2 is not supported by the server, falling back to RunResourceAction.
44+
2345
## OpenID Connect authorization code flow with PKCE is now handled by the server instead of the UI
2446

2547
Previously, when PKCE was enabled, the authorization code flow (the process which happens when you log in to Argo CD using OpenID Connect) was handled by the UI, whereas this flow was handled by the server if PKCE was not enabled. The server now always handles this flow, PKCE being enabled or not.

0 commit comments

Comments
 (0)