Skip to content

Commit

Permalink
chore: update grpc runtime library (argoproj#8929)
Browse files Browse the repository at this point in the history
* chore: update grpc POC

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* fix: register gogo codec (#1)

Signed-off-by: Alexander Matyushentsev <[email protected]>

* Remove gogo annotations from application.proto

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* Fix unit tests

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* Fix e2e test

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* Fix lint

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* Fix lint

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* Fix unit-test

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* Fix LogEntry.Last required field not populated

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* Fix LogEntry required fields

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* Fix get log content

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* Fix app actions list

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* Fix ApplicationPodLogsQuery

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* Fix RunResourceAction

Signed-off-by: Leonardo Luz Almeida <[email protected]>

Co-authored-by: Alexander Matyushentsev <[email protected]>
  • Loading branch information
leoluz and alexmt authored Apr 18, 2022
1 parent 712d9fe commit bcc69bd
Show file tree
Hide file tree
Showing 20 changed files with 1,565 additions and 1,083 deletions.
6 changes: 3 additions & 3 deletions assets/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
},
"collectionFormat": "multi",
"description": "the project names to restrict returned list applications.",
"name": "project",
"name": "projects",
"in": "query"
},
{
Expand Down Expand Up @@ -509,7 +509,7 @@
},
"collectionFormat": "multi",
"description": "the project names to restrict returned list applications.",
"name": "project",
"name": "projects",
"in": "query"
},
{
Expand Down Expand Up @@ -3147,7 +3147,7 @@
},
"collectionFormat": "multi",
"description": "the project names to restrict returned list applications.",
"name": "project",
"name": "projects",
"in": "query"
},
{
Expand Down
3 changes: 2 additions & 1 deletion cmd/argocd-git-ask-pass/commands/argocd_git_ask_pass.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/spf13/cobra"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/argoproj/argo-cd/v2/reposerver/askpass"
"github.com/argoproj/argo-cd/v2/util/errors"
Expand All @@ -35,7 +36,7 @@ func NewCommand() *cobra.Command {
if nonce == "" {
errors.CheckError(fmt.Errorf("%s is not set", git.ASKPASS_NONCE_ENV))
}
conn, err := grpc_util.BlockingDial(context.Background(), "unix", askpass.SocketPath, nil, grpc.WithInsecure())
conn, err := grpc_util.BlockingDial(context.Background(), "unix", askpass.SocketPath, nil, grpc.WithTransportCredentials(insecure.NewCredentials()))
errors.CheckError(err)
defer io.Close(conn)
client := askpass.NewAskPassServiceClient(conn)
Expand Down
96 changes: 51 additions & 45 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func NewApplicationCreateCommand(clientOpts *argocdclient.ClientOptions) *cobra.
conn, appIf := argocdClient.NewApplicationClientOrDie()
defer argoio.Close(conn)
appCreateRequest := applicationpkg.ApplicationCreateRequest{
Application: *app,
Application: app,
Upsert: &upsert,
Validate: &appOpts.Validate,
}
Expand Down Expand Up @@ -310,16 +310,16 @@ func NewApplicationLogsCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
stream, err := appIf.PodLogs(context.Background(), &applicationpkg.ApplicationPodLogsQuery{
Name: &appName,
Group: &group,
Namespace: namespace,
Namespace: pointer.String(namespace),
Kind: &kind,
ResourceName: &resourceName,
Follow: follow,
TailLines: tail,
SinceSeconds: sinceSeconds,
Follow: pointer.Bool(follow),
TailLines: pointer.Int64(tail),
SinceSeconds: pointer.Int64(sinceSeconds),
UntilTime: &untilTime,
Filter: &filter,
Container: container,
Previous: previous,
Container: pointer.String(container),
Previous: pointer.Bool(previous),
})
if err != nil {
log.Fatalf("failed to get pod logs: %v", err)
Expand All @@ -341,8 +341,8 @@ func NewApplicationLogsCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
}
log.Fatalf("stream read failed: %v", err)
}
if !msg.Last {
fmt.Println(msg.Content)
if !msg.GetLast() {
fmt.Println(msg.GetContent())
} else {
return
}
Expand Down Expand Up @@ -553,7 +553,7 @@ func NewApplicationSetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com
setParameterOverrides(app, appOpts.Parameters)
_, err = appIf.UpdateSpec(ctx, &applicationpkg.ApplicationUpdateSpecRequest{
Name: &app.Name,
Spec: app.Spec,
Spec: &app.Spec,
Validate: &appOpts.Validate,
})
errors.CheckError(err)
Expand Down Expand Up @@ -690,7 +690,7 @@ func NewApplicationUnsetCommand(clientOpts *argocdclient.ClientOptions) *cobra.C
cmdutil.SetAppSpecOptions(c.Flags(), &app.Spec, &appOpts)
_, err = appIf.UpdateSpec(context.Background(), &applicationpkg.ApplicationUpdateSpecRequest{
Name: &app.Name,
Spec: app.Spec,
Spec: &app.Spec,
Validate: &appOpts.Validate,
})
errors.CheckError(err)
Expand Down Expand Up @@ -839,7 +839,7 @@ func NewApplicationDiffCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
if revision != "" {
q := applicationpkg.ApplicationManifestQuery{
Name: &appName,
Revision: revision,
Revision: &revision,
}
res, err := appIf.GetManifests(context.Background(), &q)
errors.CheckError(err)
Expand Down Expand Up @@ -1121,7 +1121,7 @@ func NewApplicationListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
Run: func(c *cobra.Command, args []string) {
conn, appIf := headless.NewClientOrDie(clientOpts, c).NewApplicationClientOrDie()
defer argoio.Close(conn)
apps, err := appIf.List(context.Background(), &applicationpkg.ApplicationQuery{Selector: selector})
apps, err := appIf.List(context.Background(), &applicationpkg.ApplicationQuery{Selector: pointer.String(selector)})
errors.CheckError(err)
appList := apps.Items
if len(projects) != 0 {
Expand Down Expand Up @@ -1193,10 +1193,10 @@ const (
resourceFieldNameWithNamespaceCount = 2
)

func parseSelectedResources(resources []string) []argoappv1.SyncOperationResource {
var selectedResources []argoappv1.SyncOperationResource
func parseSelectedResources(resources []string) []*argoappv1.SyncOperationResource {
var selectedResources []*argoappv1.SyncOperationResource
if resources != nil {
selectedResources = []argoappv1.SyncOperationResource{}
selectedResources = []*argoappv1.SyncOperationResource{}
for _, r := range resources {
fields := strings.Split(r, resourceFieldDelimiter)
if len(fields) != resourceFieldCount {
Expand All @@ -1218,7 +1218,7 @@ func parseSelectedResources(resources []string) []argoappv1.SyncOperationResourc
Name: name,
Namespace: namespace,
}
selectedResources = append(selectedResources, rsrc)
selectedResources = append(selectedResources, &rsrc)
}
}
return selectedResources
Expand Down Expand Up @@ -1267,7 +1267,7 @@ func NewApplicationWaitCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
closer, appIf := acdClient.NewApplicationClientOrDie()
defer argoio.Close(closer)
if selector != "" {
list, err := appIf.List(context.Background(), &applicationpkg.ApplicationQuery{Selector: selector})
list, err := appIf.List(context.Background(), &applicationpkg.ApplicationQuery{Selector: pointer.String(selector)})
errors.CheckError(err)
for _, i := range list.Items {
appNames = append(appNames, i.Name)
Expand Down Expand Up @@ -1353,7 +1353,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co

appNames := args
if selector != "" {
list, err := appIf.List(context.Background(), &applicationpkg.ApplicationQuery{Selector: selector})
list, err := appIf.List(context.Background(), &applicationpkg.ApplicationQuery{Selector: pointer.String(selector)})
errors.CheckError(err)
// unlike list, we'd want to fail if nothing was found
if len(list.Items) == 0 {
Expand All @@ -1371,7 +1371,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co

q := applicationpkg.ApplicationManifestQuery{
Name: &appName,
Revision: revision,
Revision: &revision,
}

res, err := appIf.GetManifests(ctx, &q)
Expand Down Expand Up @@ -1444,10 +1444,10 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co

syncReq := applicationpkg.ApplicationSyncRequest{
Name: &appName,
DryRun: dryRun,
Revision: revision,
DryRun: &dryRun,
Revision: &revision,
Resources: selectedResources,
Prune: prune,
Prune: &prune,
Manifests: localObjsStrings,
Infos: getInfos(infos),
SyncOptions: syncOptionsFactory(),
Expand Down Expand Up @@ -1582,7 +1582,7 @@ func (rs *resourceState) Merge(newState *resourceState) bool {
return updated
}

func getResourceStates(app *argoappv1.Application, selectedResources []argoappv1.SyncOperationResource) []*resourceState {
func getResourceStates(app *argoappv1.Application, selectedResources []*argoappv1.SyncOperationResource) []*resourceState {
var states []*resourceState
resourceByKey := make(map[kube.ResourceKey]argoappv1.ResourceStatus)
for i := range app.Status.Resources {
Expand Down Expand Up @@ -1627,17 +1627,23 @@ func getResourceStates(app *argoappv1.Application, selectedResources []argoappv1
}
// filter out not selected resources
if len(selectedResources) > 0 {
r := []argoappv1.SyncOperationResource{}
for _, res := range selectedResources {
if res != nil {
r = append(r, *res)
}
}
for i := len(states) - 1; i >= 0; i-- {
res := states[i]
if !argo.ContainsSyncResource(res.Name, res.Namespace, schema.GroupVersionKind{Group: res.Group, Kind: res.Kind}, selectedResources) {
if !argo.ContainsSyncResource(res.Name, res.Namespace, schema.GroupVersionKind{Group: res.Group, Kind: res.Kind}, r) {
states = append(states[:i], states[i+1:]...)
}
}
}
return states
}

func groupResourceStates(app *argoappv1.Application, selectedResources []argoappv1.SyncOperationResource) map[string]*resourceState {
func groupResourceStates(app *argoappv1.Application, selectedResources []*argoappv1.SyncOperationResource) map[string]*resourceState {
resStates := make(map[string]*resourceState)
for _, result := range getResourceStates(app, selectedResources) {
key := result.Key()
Expand Down Expand Up @@ -1668,7 +1674,7 @@ func checkResourceStatus(watch watchOpts, healthStatus string, syncStatus string

const waitFormatString = "%s\t%5s\t%10s\t%10s\t%20s\t%8s\t%7s\t%10s\t%s\n"

func waitOnApplicationStatus(acdClient argocdclient.Client, appName string, timeout uint, watch watchOpts, selectedResources []argoappv1.SyncOperationResource) (*argoappv1.Application, error) {
func waitOnApplicationStatus(acdClient argocdclient.Client, appName string, timeout uint, watch watchOpts, selectedResources []*argoappv1.SyncOperationResource) (*argoappv1.Application, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -1921,8 +1927,8 @@ func NewApplicationRollbackCommand(clientOpts *argocdclient.ClientOptions) *cobr

_, err = appIf.Rollback(ctx, &applicationpkg.ApplicationRollbackRequest{
Name: &appName,
ID: depInfo.ID,
Prune: prune,
Id: pointer.Int64(depInfo.ID),
Prune: pointer.Bool(prune),
})
errors.CheckError(err)

Expand Down Expand Up @@ -1990,7 +1996,7 @@ func NewApplicationManifestsCommand(clientOpts *argocdclient.ClientOptions) *cob
if revision != "" {
q := applicationpkg.ApplicationManifestQuery{
Name: &appName,
Revision: revision,
Revision: pointer.String(revision),
}
res, err := appIf.GetManifests(ctx, &q)
errors.CheckError(err)
Expand Down Expand Up @@ -2079,7 +2085,7 @@ func NewApplicationEditCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co

var appOpts cmdutil.AppOptions
cmdutil.SetAppSpecOptions(c.Flags(), &app.Spec, &appOpts)
_, err = appIf.UpdateSpec(context.Background(), &applicationpkg.ApplicationUpdateSpecRequest{Name: &app.Name, Spec: updatedSpec, Validate: &appOpts.Validate})
_, err = appIf.UpdateSpec(context.Background(), &applicationpkg.ApplicationUpdateSpecRequest{Name: &app.Name, Spec: &updatedSpec, Validate: &appOpts.Validate})
if err != nil {
return fmt.Errorf("Failed to update application spec:\n%v", err)
}
Expand Down Expand Up @@ -2153,8 +2159,8 @@ func NewApplicationPatchCommand(clientOpts *argocdclient.ClientOptions) *cobra.C

patchedApp, err := appIf.Patch(context.Background(), &applicationpkg.ApplicationPatchRequest{
Name: &appName,
Patch: patch,
PatchType: patchType,
Patch: &patch,
PatchType: &patchType,
})
errors.CheckError(err)

Expand Down Expand Up @@ -2246,13 +2252,13 @@ func NewApplicationPatchResourceCommand(clientOpts *argocdclient.ClientOptions)
gvk := obj.GroupVersionKind()
_, err = appIf.PatchResource(ctx, &applicationpkg.ApplicationResourcePatchRequest{
Name: &appName,
Namespace: obj.GetNamespace(),
ResourceName: obj.GetName(),
Version: gvk.Version,
Group: gvk.Group,
Kind: gvk.Kind,
Patch: patch,
PatchType: patchType,
Namespace: pointer.String(obj.GetNamespace()),
ResourceName: pointer.String(obj.GetName()),
Version: pointer.String(gvk.Version),
Group: pointer.String(gvk.Group),
Kind: pointer.String(gvk.Kind),
Patch: pointer.String(patch),
PatchType: pointer.String(patchType),
})
errors.CheckError(err)
log.Infof("Resource '%s' patched", obj.GetName())
Expand Down Expand Up @@ -2302,11 +2308,11 @@ func NewApplicationDeleteResourceCommand(clientOpts *argocdclient.ClientOptions)
gvk := obj.GroupVersionKind()
_, err = appIf.DeleteResource(ctx, &applicationpkg.ApplicationResourceDeleteRequest{
Name: &appName,
Namespace: obj.GetNamespace(),
ResourceName: obj.GetName(),
Version: gvk.Version,
Group: gvk.Group,
Kind: gvk.Kind,
Namespace: pointer.String(obj.GetNamespace()),
ResourceName: pointer.String(obj.GetName()),
Version: pointer.String(gvk.Version),
Group: pointer.String(gvk.Group),
Kind: pointer.String(gvk.Kind),
Force: &force,
Orphan: &orphan,
})
Expand Down
21 changes: 12 additions & 9 deletions cmd/argocd/commands/app_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ghodss/yaml"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"k8s.io/utils/pointer"

"github.com/argoproj/argo-cd/v2/cmd/argocd/commands/headless"
argocdclient "github.com/argoproj/argo-cd/v2/pkg/apiclient"
Expand Down Expand Up @@ -71,10 +72,11 @@ func NewApplicationResourceActionsListCommand(clientOpts *argocdclient.ClientOpt
gvk := obj.GroupVersionKind()
availActionsForResource, err := appIf.ListResourceActions(ctx, &applicationpkg.ApplicationResourceRequest{
Name: &appName,
Namespace: obj.GetNamespace(),
ResourceName: obj.GetName(),
Group: gvk.Group,
Kind: gvk.Kind,
Namespace: pointer.String(obj.GetNamespace()),
ResourceName: pointer.String(obj.GetName()),
Group: pointer.String(gvk.Group),
Kind: pointer.String(gvk.Kind),
Version: pointer.String(gvk.GroupVersion().Version),
})
errors.CheckError(err)
for _, action := range availActionsForResource.Actions {
Expand Down Expand Up @@ -162,11 +164,12 @@ func NewApplicationResourceActionsRunCommand(clientOpts *argocdclient.ClientOpti
objResourceName := obj.GetName()
_, err := appIf.RunResourceAction(context.Background(), &applicationpkg.ResourceActionRunRequest{
Name: &appName,
Namespace: obj.GetNamespace(),
ResourceName: objResourceName,
Group: gvk.Group,
Kind: gvk.Kind,
Action: actionName,
Namespace: pointer.String(obj.GetNamespace()),
ResourceName: pointer.String(objResourceName),
Group: pointer.String(gvk.Group),
Kind: pointer.String(gvk.Kind),
Version: pointer.String(gvk.GroupVersion().Version),
Action: pointer.String(actionName),
})
errors.CheckError(err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmpserver/apiclient/clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

grpc_util "github.com/argoproj/argo-cd/v2/util/grpc"
"github.com/argoproj/argo-cd/v2/util/io"
Expand Down Expand Up @@ -47,7 +48,7 @@ func NewConnection(address string) (*grpc.ClientConn, error) {
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxGRPCMessageSize), grpc.MaxCallSendMsgSize(MaxGRPCMessageSize)),
}

dialOpts = append(dialOpts, grpc.WithInsecure())
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc_util.BlockingDial(context.Background(), "unix", address, nil, dialOpts...)
if err != nil {
log.Errorf("Unable to connect to config management plugin service with address %s", address)
Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ require (
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa
google.golang.org/grpc v1.42.0
google.golang.org/protobuf v1.27.1
google.golang.org/grpc v1.45.0
google.golang.org/protobuf v1.28.0
gopkg.in/go-playground/webhooks.v5 v5.11.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.23.3
Expand Down Expand Up @@ -240,8 +240,6 @@ replace (
github.com/grpc-ecosystem/grpc-gateway => github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/improbable-eng/grpc-web => github.com/improbable-eng/grpc-web v0.0.0-20181111100011-16092bd1d58a

google.golang.org/grpc => google.golang.org/grpc v1.15.0

// https://github.com/kubernetes/kubernetes/issues/79384#issuecomment-505627280
k8s.io/api => k8s.io/api v0.23.1
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.23.1
Expand Down
Loading

0 comments on commit bcc69bd

Please sign in to comment.