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(in-cluster): do not allow the cluster to be used when disabled #21208

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3057a28
fix(in-cluster): do not allow the cluster to be used when disabled
agaudreault Dec 16, 2024
eb4a528
typo
agaudreault Dec 17, 2024
ca03d10
linter
agaudreault Dec 17, 2024
6ec28fc
Merge remote-tracking branch 'upstream/master' into fix-in-cluster-di…
agaudreault Dec 17, 2024
0a72dd8
e2e
agaudreault Dec 18, 2024
35d6ec0
fix e2e
agaudreault Dec 18, 2024
c96ecd8
unquote CLI error
agaudreault Dec 18, 2024
224869d
Revert "unquote CLI error"
agaudreault Dec 18, 2024
7fad375
just match the quoted result
agaudreault Dec 18, 2024
d5a0c64
Merge remote-tracking branch 'upstream/master' into fix-in-cluster-di…
agaudreault Dec 18, 2024
223171a
Merge branch 'master' into fix-in-cluster-disable
agaudreault Dec 19, 2024
ac39de3
Merge branch 'master' into fix-in-cluster-disable
agaudreault Jan 3, 2025
3e71bac
Merge remote-tracking branch 'upstream/master' into fix-in-cluster-di…
agaudreault Jan 3, 2025
92321c2
fix merge
agaudreault Jan 3, 2025
6fe112d
fix some tests
agaudreault Jan 3, 2025
0b8adef
lint
agaudreault Jan 3, 2025
929b23d
linter
agaudreault Jan 3, 2025
9bd1f1f
code review
agaudreault Jan 6, 2025
36a1971
Merge branch 'master' into fix-in-cluster-disable
agaudreault Jan 8, 2025
14dc2d2
Merge remote-tracking branch 'upstream/master' into fix-in-cluster-di…
agaudreault Jan 17, 2025
1d96b84
add migration docs
agaudreault Jan 17, 2025
7819589
fix tests
agaudreault Jan 17, 2025
259dda4
fix tests
agaudreault Jan 17, 2025
da9bc98
Merge remote-tracking branch 'upstream/master' into fix-in-cluster-di…
agaudreault Jan 17, 2025
8e1bd59
lint
agaudreault Jan 17, 2025
815dff5
fix test
agaudreault Jan 17, 2025
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
49 changes: 39 additions & 10 deletions applicationset/controllers/applicationset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,39 @@ import (
"github.com/argoproj/argo-cd/v3/util/settings"
)

// getDefaultTestClientSet creates a Clientset with the default argo objects
// and objects specified in parameters
func getDefaultTestClientSet(obj ...runtime.Object) *kubefake.Clientset {
argoCDSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: argocommon.ArgoCDSecretName,
Namespace: "argocd",
Labels: map[string]string{
"app.kubernetes.io/part-of": "argocd",
},
},
Data: map[string][]byte{
"admin.password": nil,
"server.secretkey": nil,
},
}

emptyArgoCDConfigMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: argocommon.ArgoCDConfigMapName,
Namespace: "argocd",
Labels: map[string]string{
"app.kubernetes.io/part-of": "argocd",
},
},
Data: map[string]string{},
}

objects := append(obj, emptyArgoCDConfigMap, argoCDSecret)
kubeclientset := kubefake.NewClientset(objects...)
return kubeclientset
}

func TestCreateOrUpdateInCluster(t *testing.T) {
scheme := runtime.NewScheme()
err := v1alpha1.AddToScheme(scheme)
Expand Down Expand Up @@ -1317,8 +1350,7 @@ func TestRemoveFinalizerOnInvalidDestination_DestinationTypes(t *testing.T) {
},
}

objects := append([]runtime.Object{}, secret)
kubeclientset := kubefake.NewSimpleClientset(objects...)
kubeclientset := getDefaultTestClientSet(secret)
metrics := appsetmetrics.NewFakeAppsetMetrics()

argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)
Expand Down Expand Up @@ -2054,8 +2086,7 @@ func TestValidateGeneratedApplications(t *testing.T) {
},
}

objects := append([]runtime.Object{}, secret)
kubeclientset := kubefake.NewSimpleClientset(objects...)
kubeclientset := getDefaultTestClientSet(secret)

argodb := db.NewDB("argocd", settings.NewSettingsManager(context.TODO(), kubeclientset, "argocd"), kubeclientset)

Expand Down Expand Up @@ -2117,7 +2148,7 @@ func TestReconcilerValidationProjectErrorBehaviour(t *testing.T) {
},
}

kubeclientset := kubefake.NewSimpleClientset()
kubeclientset := getDefaultTestClientSet()

client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet, &project).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
metrics := appsetmetrics.NewFakeAppsetMetrics()
Expand Down Expand Up @@ -2404,8 +2435,7 @@ func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
},
}

objects := append([]runtime.Object{}, secret)
kubeclientset := kubefake.NewSimpleClientset(objects...)
kubeclientset := getDefaultTestClientSet(secret)

client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet, &defaultProject).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
metrics := appsetmetrics.NewFakeAppsetMetrics()
Expand Down Expand Up @@ -2580,8 +2610,7 @@ func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alp
},
}

objects := append([]runtime.Object{}, secret)
kubeclientset := kubefake.NewSimpleClientset(objects...)
kubeclientset := getDefaultTestClientSet(secret)

client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(&appSet, &defaultProject).WithStatusSubresource(&appSet).WithIndex(&v1alpha1.Application{}, ".metadata.controller", appControllerIndexer).Build()
metrics := appsetmetrics.NewFakeAppsetMetrics()
Expand Down Expand Up @@ -2700,7 +2729,7 @@ func TestPolicies(t *testing.T) {
Spec: v1alpha1.AppProjectSpec{SourceRepos: []string{"*"}, Destinations: []v1alpha1.ApplicationDestination{{Namespace: "*", Server: "https://kubernetes.default.svc"}}},
}

kubeclientset := kubefake.NewSimpleClientset()
kubeclientset := getDefaultTestClientSet()

for _, c := range []struct {
name string
Expand Down
20 changes: 17 additions & 3 deletions cmd/argocd/commands/admin/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
kubefake "k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/tools/cache"

"github.com/argoproj/argo-cd/v3/common"
statecache "github.com/argoproj/argo-cd/v3/controller/cache"
cachemocks "github.com/argoproj/argo-cd/v3/controller/cache/mocks"
"github.com/argoproj/argo-cd/v3/controller/metrics"
Expand Down Expand Up @@ -57,15 +58,28 @@ func TestGetReconcileResults(t *testing.T) {
func TestGetReconcileResults_Refresh(t *testing.T) {
ctx := context.Background()

cm := corev1.ConfigMap{
argoCM := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "argocd-cm",
Name: common.ArgoCDConfigMapName,
Namespace: "default",
Labels: map[string]string{
"app.kubernetes.io/part-of": "argocd",
},
},
}
argoCDSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: common.ArgoCDSecretName,
Namespace: "default",
Labels: map[string]string{
"app.kubernetes.io/part-of": "argocd",
},
},
Data: map[string][]byte{
"admin.password": nil,
"server.secretkey": nil,
},
}
proj := &v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
Expand All @@ -91,7 +105,7 @@ func TestGetReconcileResults_Refresh(t *testing.T) {

appClientset := appfake.NewSimpleClientset(app, proj)
deployment := test.NewDeployment()
kubeClientset := kubefake.NewClientset(deployment, &cm)
kubeClientset := kubefake.NewClientset(deployment, argoCM, argoCDSecret)
clusterCache := clustermocks.ClusterCache{}
clusterCache.On("IsNamespaced", mock.Anything).Return(true, nil)
clusterCache.On("GetGVKParser", mock.Anything).Return(nil)
Expand Down
13 changes: 13 additions & 0 deletions docs/operator-manual/upgrading/2.14-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,16 @@ The v2 behavior can be preserved by setting the config value `server.rbac.disabl
to `false` in the Argo CD ConfigMap `argocd-cm`.

Read the [RBAC documentation](../rbac.md#fine-grained-permissions-for-updatedelete-action) for more detailed inforamtion.

## Other changes

### Using `cluster.inClusterEnabled: "false"`

When `cluster.inClusterEnabled: "false"` is explicitly configured, Applications currently configured to
sync on the in-cluster cluster will now be in an Unknown state, without the possibility to sync resources.

It will not be possible to create new Applications using the in-cluster cluster. When deleting existing
Application, it will not delete the previously managed resources.

It is recommended to perform any cleanup or migration to existing in-cluster Application before upgrading
when in-cluster is disabled. To perform cleanup post-migration, the in-cluster will need to be enabled temporarily.
59 changes: 47 additions & 12 deletions test/e2e/app_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,28 @@ func TestComparisonFailsIfClusterNotAdded(t *testing.T) {
Expect(DoesNotExist())
}

func TestComparisonFailsIfInClusterDisabled(t *testing.T) {
Given(t).
Path(guestbookPath).
DestServer(KubernetesInternalAPIServerAddr).
When().
CreateApp().
Refresh(RefreshTypeNormal).
Sync().
Then().
Expect(Success("")).
Expect(HealthIs(health.HealthStatusHealthy)).
Expect(SyncStatusIs(SyncStatusCodeSynced)).
When().
SetParamInSettingConfigMap("cluster.inClusterEnabled", "false").
Refresh(RefreshTypeNormal).
Then().
Expect(Success("")).
Expect(HealthIs(health.HealthStatusUnknown)).
Expect(SyncStatusIs(SyncStatusCodeUnknown)).
Expect(Condition(ApplicationConditionInvalidSpecError, fmt.Sprintf("cluster %q is disabled", KubernetesInternalAPIServerAddr)))
}

func TestCannotSetInvalidPath(t *testing.T) {
Given(t).
Path(guestbookPath).
Expand Down Expand Up @@ -1115,34 +1137,34 @@ definitions:
end
return _copy(object)
end

job = {}
job.apiVersion = "batch/v1"
job.kind = "Job"

job.metadata = {}
job.metadata.name = obj.metadata.name .. "-123"
job.metadata.namespace = obj.metadata.namespace

ownerRef = {}
ownerRef.apiVersion = obj.apiVersion
ownerRef.kind = obj.kind
ownerRef.name = obj.metadata.name
ownerRef.uid = obj.metadata.uid
job.metadata.ownerReferences = {}
job.metadata.ownerReferences[1] = ownerRef

job.spec = {}
job.spec.suspend = false
job.spec.template = {}
job.spec.template.spec = deepCopy(obj.spec.jobTemplate.spec.template.spec)

impactedResource = {}
impactedResource.operation = "create"
impactedResource.resource = job
result = {}
result[1] = impactedResource

return result`

func TestNewStyleResourceActionPermitted(t *testing.T) {
Expand Down Expand Up @@ -1219,28 +1241,28 @@ definitions:
end
return _copy(object)
end

job = {}
job.apiVersion = "batch/v1"
job.kind = "Job"

job.metadata = {}
job.metadata.name = obj.metadata.name .. "-123"
job.metadata.namespace = obj.metadata.namespace

ownerRef = {}
ownerRef.apiVersion = obj.apiVersion
ownerRef.kind = obj.kind
ownerRef.name = obj.metadata.name
ownerRef.uid = obj.metadata.uid
job.metadata.ownerReferences = {}
job.metadata.ownerReferences[1] = ownerRef

job.spec = {}
job.spec.suspend = false
job.spec.template = {}
job.spec.template.spec = deepCopy(obj.spec.jobTemplate.spec.template.spec)

impactedResource1 = {}
impactedResource1.operation = "create"
impactedResource1.resource = job
Expand All @@ -1253,7 +1275,7 @@ definitions:
impactedResource2.resource = obj

result[2] = impactedResource2

return result`

func TestNewStyleResourceActionMixedOk(t *testing.T) {
Expand Down Expand Up @@ -2158,6 +2180,19 @@ func TestCreateAppWithNoNameSpaceWhenRequired2(t *testing.T) {
})
}

func TestCreateAppWithInClusterDisabled(t *testing.T) {
Given(t).
Path(guestbookPath).
DestServer(KubernetesInternalAPIServerAddr).
When().
SetParamInSettingConfigMap("cluster.inClusterEnabled", "false").
IgnoreErrors().
CreateApp().
Then().
// RPC error messages are quoted: time="2024-12-18T04:13:58Z" level=fatal msg="<Quoted value>"
Expect(Error("", fmt.Sprintf(`cluster \"%s\" is disabled`, KubernetesInternalAPIServerAddr)))
}

func TestListResource(t *testing.T) {
fixture.SkipOnEnv(t, "OPENSHIFT")
Given(t).
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fixture/app/expectation.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func Error(message, err string, matchers ...func(string, string) bool) Expectati
return failed, fmt.Sprintf("output does not contain '%s'", message)
}
if !match(c.actions.lastError.Error(), err) {
return failed, fmt.Sprintf("error does not contain '%s'", message)
return failed, fmt.Sprintf("error does not contain '%s'", err)
}
return succeeded, fmt.Sprintf("error '%s'", message)
}
Expand Down
Loading
Loading