Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into mc/cli-docs-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-crespo-fdc committed Aug 27, 2024
2 parents b2a95d0 + 0fd4d59 commit b975e9c
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 48 deletions.
4 changes: 2 additions & 2 deletions charts/kuberpult/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ spec:
{{- end }}
{{- if .Values.ingress.allowedPaths.ui }}
# UI bootstrapping:
- pathType: ImplementationSpecific
path: /ui/*
- pathType: Prefix
path: /ui/
backend:
service:
name: kuberpult-frontend-service
Expand Down
2 changes: 1 addition & 1 deletion charts/kuberpult/tests/charts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ func makeAllIngressPaths(withDex, withUi, withOldApi, withNewApi bool) []network
}
if withUi {
result = append(result,
makeIngressImplementationSpecificPath("/ui/*"),
makeIngressPrefixPath("/ui/"),
makeIngressExactPath("/"),
makeIngressPrefixPath("/static/js/"),
makeIngressPrefixPath("/static/css/"),
Expand Down
8 changes: 4 additions & 4 deletions services/rollout-service/pkg/argo/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"path/filepath"
"slices"
Expand Down Expand Up @@ -173,12 +174,11 @@ func (a ArgoAppProcessor) CreateOrUpdateApp(ctx context.Context, overview *api.G
Project: conversion.FromString(appToUpdate.Spec.Project),
}

//exhaustruct:ignore
emptyAppSpec := v1alpha1.ApplicationSpec{}
//We have to exclude the unexported type destination and the syncPolicy
//exhaustruct:ignore
diff := cmp.Diff(appUpdateRequest.Application.Spec, existingApp.Spec,
cmp.AllowUnexported(emptyAppSpec.Destination),
cmp.AllowUnexported(emptyAppSpec.SyncPolicy))
cmp.AllowUnexported(v1alpha1.ApplicationDestination{}),
cmpopts.IgnoreTypes(v1alpha1.SyncPolicy{}))
if diff != "" {
updateSpan, ctx := tracer.StartSpanFromContext(ctx, "UpdateApplications")
updateSpan.SetTag("application", app.Name)
Expand Down
81 changes: 77 additions & 4 deletions services/rollout-service/pkg/argo/argo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (a *mockArgoProcessor) checkEvent(ev *v1alpha1.ApplicationWatchEvent) bool
return false
}

func (a *mockArgoProcessor) Consume(t *testing.T, ctx context.Context, expectedTypes []string, existingArgoApps bool) error {
func (a *mockArgoProcessor) Consume(t *testing.T, ctx context.Context, expectedTypes []string, existingArgoApps bool, syncDisable bool) error {
appsKnownToArgo := map[string]map[string]*v1alpha1.Application{}
envAppsKnownToArgo := make(map[string]*v1alpha1.Application)

Expand All @@ -133,7 +133,18 @@ func (a *mockArgoProcessor) Consume(t *testing.T, ctx context.Context, expectedT

for _, app := range env.Applications {
if existingArgoApps {
envAppsKnownToArgo[app.Name] = CreateArgoApplication(overview, app, env)
argoApp := CreateArgoApplication(overview, app, env)
if syncDisable {
argoApp.Spec.SyncPolicy = &v1alpha1.SyncPolicy{
Automated: &v1alpha1.SyncPolicyAutomated{
Prune: false,
SelfHeal: false,
AllowEmpty: false,
},
}
}
envAppsKnownToArgo[app.Name] = argoApp

appsKnownToArgo[env.Name] = envAppsKnownToArgo
}
a.CreateOrUpdateApp(ctx, overview, app, env, envAppsKnownToArgo)
Expand Down Expand Up @@ -258,6 +269,7 @@ func TestArgoConsume(t *testing.T) {
ExpectedConsumed int
ExpectedConsumedTypes []string
ExistingArgoApps bool
SyncDisable bool
}{
{
Name: "when ctx in cancelled no app is processed",
Expand Down Expand Up @@ -673,6 +685,62 @@ func TestArgoConsume(t *testing.T) {
ExpectedConsumedTypes: []string{},
ExistingArgoApps: true,
},
{
Name: "one application in the overview but no event is consumed",
Steps: []step{
{
RecvErr: status.Error(codes.Canceled, "context cancelled"),
CancelContext: true,
},
},
Overview: &api.GetOverviewResponse{
Applications: map[string]*api.Application{
"foo": {
Releases: []*api.Release{
{
Version: 1,
SourceCommitId: "00001",
},
},
Team: "footeam",
},
},
EnvironmentGroups: []*api.EnvironmentGroup{
{

EnvironmentGroupName: "staging-group",
Environments: []*api.Environment{
{
Name: "staging",
Applications: map[string]*api.Environment_Application{
"foo": {
Name: "foo",
Version: 1,
DeploymentMetaData: &api.Environment_Application_DeploymentMetaData{
DeployTime: "123456789",
},
},
},
Priority: api.Priority_UPSTREAM,
Config: &api.EnvironmentConfig{
Argocd: &api.EnvironmentConfig_ArgoCD{
Destination: &api.EnvironmentConfig_ArgoCD_Destination{
Name: "staging",
Server: "test-server",
},
},
},
},
},
},
},
GitRevision: "1234",
},
ExpectedConsumed: 0,
ExpectedConsumedTypes: []string{},
ExistingArgoApps: true,
SyncDisable: true,
},
}
for _, tc := range tcs {
tc := tc
Expand All @@ -694,7 +762,7 @@ func TestArgoConsume(t *testing.T) {
hlth.BackOffFactory = func() backoff.BackOff { return backoff.NewConstantBackOff(0) }
errCh := make(chan error)
go func() {
errCh <- argoProcessor.Consume(t, ctx, tc.ExpectedConsumedTypes, tc.ExistingArgoApps)
errCh <- argoProcessor.Consume(t, ctx, tc.ExpectedConsumedTypes, tc.ExistingArgoApps, tc.SyncDisable)
}()

go func() {
Expand Down Expand Up @@ -771,8 +839,13 @@ func (a mockArgoProcessor) CreateOrUpdateApp(ctx context.Context, overview *api.
Application: appToUpdate,
Project: conversion.FromString(appToUpdate.Spec.Project),
}
//We have to exclude the unexported type destination and the syncPolicy
//exhaustruct:ignore
diff := cmp.Diff(appUpdateRequest.Application.Spec, existingApp.Spec,
cmp.AllowUnexported(v1alpha1.ApplicationDestination{}),
cmpopts.IgnoreTypes(v1alpha1.SyncPolicy{}))

if !cmp.Equal(appUpdateRequest.Application.Spec, existingApp.Spec, cmp.AllowUnexported(v1alpha1.ApplicationSpec{}.Destination)) {
if diff != "" {
a.ApplicationClient.Update(ctx, appUpdateRequest)
}
}
Expand Down
18 changes: 8 additions & 10 deletions tests/integration-tests/cluster-setup/argocd-kuberpult.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ $(sed -e "s/^/ /" </kp/known_hosts)
cm:
accounts.kuberpult: apiKey
timeout.reconciliation: 0s
params:
controller.repo.server.plaintext: "true"
server.repo.server.plaintext: "true"
repo.server: kuberpult-cd-service:8443
rbac:
policy.csv: |
p, role:kuberpult, applications, refresh, */*, allow
Expand Down Expand Up @@ -168,21 +164,21 @@ rollout:
resources:
limits:
memory: 200Mi
cpu: 0.05
cpu: 0.2
requests:
memory: 200Mi
cpu: 0.05
cpu: 0.2
manifestRepoExport:
eslProcessingIdleTimeSeconds: 15
eslProcessingIdleTimeSeconds: 1
resources:
limits:
memory: 200Mi
cpu: 0.05
cpu: 0.2
requests:
memory: 200Mi
cpu: 0.05
cpu: 0.2
manageArgoApplications:
enabled: true
enabled: false
ingress:
domainName: kuberpult.example.com
log:
Expand Down Expand Up @@ -228,6 +224,8 @@ print "connection to frontend service successful"
waitForDeployment "default" "app=kuberpult-rollout-service"
waitForDeployment "default" "app=kuberpult-manifest-repo-export-service"

portForwardAndWait "default" deploy/postgres "5432" "5432"

kubectl get deployment
kubectl get pods

Expand Down
3 changes: 2 additions & 1 deletion tests/integration-tests/cluster-setup/setup-cluster-ssh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ apiVersion: v1
kind: Secret
metadata:
name: my-private-ssh-repo
namespace: default
labels:
argocd.argoproj.io/secret-type: repository
namespace: ${ARGO_NAMESPACE}
stringData:
project: test-env
insecure: "true"
url: ssh://git@server.${GIT_NAMESPACE}.svc.cluster.local/git/repos/manifests
sshPrivateKey: |
$(sed -e "s/^/ /" <"$scratch"/client)
Expand Down
16 changes: 0 additions & 16 deletions tests/integration-tests/cluster-setup/setup-postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,6 @@ function waitForDeployment() {
done
}

function portForwardAndWait() {
ns="$1"
deployment="$2"
portHere="$3"
portThere="$4"
ports="$portHere:$portThere"
print "portForwardAndWait for $ns/$deployment $ports"
kubectl -n "$ns" port-forward "$deployment" "$ports" &
print "portForwardAndWait: waiting until the port forward works..."
until nc -vz localhost "$portHere"
do
sleep 1s
done
}

kubectl apply -f - <<EOF
---
apiVersion: v1
Expand Down Expand Up @@ -87,5 +72,4 @@ spec:
EOF

waitForDeployment default "app=postgres"
portForwardAndWait "default" deploy/postgres "5432" "5432"
echo "done setting up postgres"
24 changes: 14 additions & 10 deletions tests/integration-tests/rollout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os/exec"
"strings"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -55,22 +56,21 @@ func TestArgoRolloutWork(t *testing.T) {
name string
app string
}{
// TODO this will be fixed in Ref SRX-PA568W
//{
// name: "it can sync manifests into the cluster",
// app: "rollout-" + appSuffix,
//},
{
name: "it can sync manifests into the cluster",
app: "rollout-" + appSuffix,
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
appName := "development-" + tc.app
appName := "development2-" + tc.app
expectedConfig := simplifiedConfigMap{
ApiVersion: "v1",
Kind: "ConfigMap",
Metadata: simplifiedConfigMapMeta{
Name: tc.app,
Namespace: "development",
Namespace: "development2",
},
Data: map[string]string{
"key": tc.app,
Expand All @@ -82,8 +82,9 @@ func TestArgoRolloutWork(t *testing.T) {
}
// Release a new app that we start completely fresh
releaseApp(t, tc.app, map[string]string{
"development": string(data),
"development2": string(data),
})
time.Sleep(10 * time.Second)
// We have to sync the root app once because we have created a new app
runArgo(t, "app", "sync", "root")
// The sync may already be in progress, therefore we wait here for pending operations to finish
Expand Down Expand Up @@ -118,7 +119,7 @@ func TestArgoRolloutWork(t *testing.T) {

func runArgo(t *testing.T, args ...string) (*exec.Cmd, []byte) {
var out, stderr bytes.Buffer
args = append([]string{"--port-forward"}, args...)
args = append([]string{"--port-forward", "--grpc-web"}, args...)
cmd := exec.Command("argocd", args...)
cmd.Stdout = &out
cmd.Stderr = &stderr
Expand All @@ -134,7 +135,10 @@ func runArgo(t *testing.T, args ...string) (*exec.Cmd, []byte) {

func releaseApp(t *testing.T, application string, manifests map[string]string) {
values := map[string]io.Reader{
"application": strings.NewReader(application),
"application": strings.NewReader(application),
"version": strings.NewReader("12"),
"source_commit_id": strings.NewReader("0123456789abcdef0123456789abcdef01234567"),
"team": strings.NewReader("team"),
}
files := map[string]io.Reader{}
for env, data := range manifests {
Expand Down

0 comments on commit b975e9c

Please sign in to comment.