-
Notifications
You must be signed in to change notification settings - Fork 351
chore: add e2e tests for argocd-agent web-based terminal feature #1107
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
Open
jparsai
wants to merge
3
commits into
redhat-developer:master
Choose a base branch
from
jparsai:agent-terminal-e2e
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
test/openshift/e2e/ginkgo/fixture/argocdclient/fixture.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| /* | ||
| Copyright 2026. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package argocdclient | ||
|
|
||
| import ( | ||
| "crypto/tls" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| "net/url" | ||
| "strings" | ||
| "sync" | ||
| "time" | ||
|
|
||
| "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" | ||
| "github.com/gorilla/websocket" | ||
| ) | ||
|
|
||
| // TerminalClient represents a test client for terminal WebSocket connections. | ||
| type TerminalClient struct { | ||
| wsConn *websocket.Conn | ||
| mu sync.Mutex | ||
| closed bool | ||
| output strings.Builder | ||
| outputMu sync.Mutex | ||
| } | ||
|
|
||
| // ExecTerminal opens a terminal session to a pod via WebSocket. | ||
| // This replicates the behavior of the ArgoCD UI when a user opens a terminal session to an application. | ||
| // ArgoCD decides which shell to use based on the configured allowed shells. | ||
| func ExecTerminal(endpoint, token string, app *v1alpha1.Application, namespace, podName, container string) (*TerminalClient, error) { | ||
| u := &url.URL{ | ||
| Scheme: "wss", | ||
| Host: endpoint, | ||
| Path: "/terminal", | ||
| } | ||
|
|
||
| q := u.Query() | ||
| q.Set("pod", podName) | ||
| q.Set("container", container) | ||
| q.Set("appName", app.Name) | ||
| q.Set("appNamespace", app.Namespace) | ||
| q.Set("projectName", app.Spec.Project) | ||
| q.Set("namespace", namespace) | ||
| u.RawQuery = q.Encode() | ||
|
|
||
| dialer := websocket.Dialer{ | ||
| TLSClientConfig: &tls.Config{ | ||
| InsecureSkipVerify: true, // #nosec G402 | ||
| }, | ||
| } | ||
|
|
||
| headers := http.Header{} | ||
| headers.Set("Cookie", fmt.Sprintf("argocd.token=%s", token)) | ||
|
|
||
| wsConn, resp, err := dialer.Dial(u.String(), headers) | ||
| if err != nil { | ||
| if resp != nil { | ||
| defer resp.Body.Close() | ||
| body, _ := io.ReadAll(resp.Body) | ||
| return nil, fmt.Errorf("failed to connect to terminal WebSocket: %w (status: %d, body: %s)", err, resp.StatusCode, string(body)) | ||
| } | ||
| return nil, fmt.Errorf("failed to connect to terminal WebSocket: %w", err) | ||
| } | ||
|
|
||
| session := &TerminalClient{ | ||
| wsConn: wsConn, | ||
| } | ||
|
|
||
| go session.readOutput() | ||
|
|
||
| return session, nil | ||
| } | ||
|
|
||
| // terminalMessage is the JSON message format used by ArgoCD terminal WebSocket | ||
| type terminalMessage struct { | ||
| Operation string `json:"operation"` | ||
| Data string `json:"data"` | ||
| Rows uint16 `json:"rows"` | ||
| Cols uint16 `json:"cols"` | ||
| } | ||
|
|
||
| // readOutput continuously reads output from the WebSocket connection | ||
| func (s *TerminalClient) readOutput() { | ||
| for { | ||
| _, message, err := s.wsConn.ReadMessage() | ||
| if err != nil { | ||
| // Connection closed or error | ||
| return | ||
| } | ||
|
|
||
| if len(message) < 1 { | ||
| continue | ||
| } | ||
|
|
||
| // Parse JSON message | ||
| var msg terminalMessage | ||
| if err := json.Unmarshal(message, &msg); err != nil { | ||
| continue | ||
| } | ||
|
|
||
| switch msg.Operation { | ||
| case "stdout": | ||
| s.outputMu.Lock() | ||
| s.output.WriteString(msg.Data) | ||
| s.outputMu.Unlock() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // SendInput sends input to the terminal session | ||
| func (s *TerminalClient) SendInput(input string) error { | ||
| s.mu.Lock() | ||
| defer s.mu.Unlock() | ||
|
|
||
| if s.closed { | ||
| return errors.New("session is closed") | ||
| } | ||
|
|
||
| // ArgoCD terminal uses JSON messages (includes rows/cols like the UI) | ||
| msg, err := json.Marshal(terminalMessage{ | ||
| Operation: "stdin", | ||
| Data: input, | ||
| Rows: 24, | ||
| Cols: 80, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return s.wsConn.WriteMessage(websocket.TextMessage, msg) | ||
| } | ||
|
|
||
| // SendResize sends a terminal resize message | ||
| func (s *TerminalClient) SendResize(cols, rows uint16) error { | ||
| s.mu.Lock() | ||
| defer s.mu.Unlock() | ||
|
|
||
| if s.closed { | ||
| return errors.New("session is closed") | ||
| } | ||
|
|
||
| // ArgoCD terminal uses JSON messages | ||
| msg, err := json.Marshal(terminalMessage{ | ||
| Operation: "resize", | ||
| Cols: cols, | ||
| Rows: rows, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return s.wsConn.WriteMessage(websocket.TextMessage, msg) | ||
| } | ||
|
|
||
| // GetOutput returns all captured output so far | ||
| func (s *TerminalClient) GetOutput() string { | ||
| s.outputMu.Lock() | ||
| defer s.outputMu.Unlock() | ||
| return s.output.String() | ||
| } | ||
|
|
||
| // WaitForOutput waits until the output contains the expected string or timeout | ||
| func (s *TerminalClient) WaitForOutput(expected string, timeout time.Duration) bool { | ||
| deadline := time.Now().Add(timeout) | ||
| for time.Now().Before(deadline) { | ||
| if strings.Contains(s.GetOutput(), expected) { | ||
| return true | ||
| } | ||
| time.Sleep(100 * time.Millisecond) | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // Close closes the terminal session | ||
| func (s *TerminalClient) Close() error { | ||
| s.mu.Lock() | ||
| defer s.mu.Unlock() | ||
|
|
||
| if s.closed { | ||
| return nil | ||
| } | ||
| s.closed = true | ||
| return s.wsConn.Close() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -516,7 +516,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { | |
| It("Should deploy ArgoCD principal and agent instances in both modes and verify they are working as expected", func() { | ||
|
|
||
| By("Deploy principal and verify it starts successfully") | ||
| deployPrincipal(ctx, k8sClient, registerCleanup) | ||
| deployPrincipal(ctx, k8sClient, registerCleanup, false) | ||
|
|
||
| By("Deploy managed agent and verify it starts successfully") | ||
| deployAgent(ctx, k8sClient, registerCleanup, argov1beta1api.AgentModeManaged) | ||
|
|
@@ -609,7 +609,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() { | |
| // This function deploys the principal ArgoCD instance and waits for it to be ready. | ||
| // It creates the required secrets for the principal and verifies that the principal deployment is in Ready state. | ||
| // It also verifies that the principal logs contain the expected messages. | ||
| func deployPrincipal(ctx context.Context, k8sClient client.Client, registerCleanup func(func())) { | ||
| func deployPrincipal(ctx context.Context, k8sClient client.Client, registerCleanup func(func()), enableServerRoute bool) { | ||
| GinkgoHelper() | ||
|
|
||
| nsPrincipal, cleanup := fixture.CreateNamespaceWithCleanupFunc(namespaceAgentPrincipal) | ||
|
|
@@ -624,6 +624,12 @@ func deployPrincipal(ctx context.Context, k8sClient client.Client, registerClean | |
| waitForLoadBalancer = false | ||
| } | ||
|
|
||
| if enableServerRoute { | ||
| argoCDInstance.Spec.Server.Route = argov1beta1api.ArgoCDRouteSpec{ | ||
| Enabled: true, | ||
| } | ||
| } | ||
|
|
||
| Expect(k8sClient.Create(ctx, argoCDInstance)).To(Succeed()) | ||
|
|
||
| By("Wait for principal service to be ready and use LoadBalancer hostname/IP when available") | ||
|
|
@@ -678,7 +684,7 @@ func deployPrincipal(ctx context.Context, k8sClient client.Client, registerClean | |
|
|
||
| Eventually(&appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{ | ||
| Name: deploymentNameAgentPrincipal, | ||
| Namespace: nsPrincipal.Name}}, "120s", "5s").Should(deploymentFixture.HaveReadyReplicas(1)) | ||
| Namespace: nsPrincipal.Name}}, "240s", "5s").Should(deploymentFixture.HaveReadyReplicas(1)) | ||
|
|
||
| By("Verify principal logs contain expected messages") | ||
|
|
||
|
|
@@ -770,7 +776,8 @@ func buildArgoCDResource(argoCDName string, componentType argov1beta1api.AgentCo | |
| Enabled: ptr.To(true), | ||
| Auth: "mtls:CN=([^,]+)", | ||
| LogLevel: "info", | ||
| Image: common.ArgoCDAgentPrincipalDefaultImageName, | ||
| // TODO: Use the argocd-agent image once it is released | ||
| Image: "quay.io/jparsai/argocd-agent:1.20.1", | ||
| Namespace: &argov1beta1api.PrincipalNamespaceSpec{ | ||
| AllowedNamespaces: []string{ | ||
| managedAgentClusterName, | ||
|
|
@@ -816,7 +823,8 @@ func buildArgoCDResource(argoCDName string, componentType argov1beta1api.AgentCo | |
| Enabled: ptr.To(true), | ||
| Creds: "mtls:any", | ||
| LogLevel: "info", | ||
| Image: common.ArgoCDAgentAgentDefaultImageName, | ||
| // TODO: Use the argocd-agent image once it is released | ||
| Image: "quay.io/jparsai/argocd-agent:1.20.1", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
| Client: &argov1beta1api.AgentClientSpec{ | ||
| PrincipalServerAddress: "", // will be set in the test | ||
| PrincipalServerPort: "443", | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than using a personal image, lets wait for
ArgoCDAgentPrincipalDefaultImageNameto be updated in upstream before we merge.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, since 0.8.x release out, now we have agent image available having fix for OCP. I raised upstream PR, will wait for it to be merged first argoproj-labs/argocd-operator#2157