Skip to content

Commit a5b5ba9

Browse files
authored
Merge pull request #234 from ShyamsundarR/bz2270175-dr
Bug 2270175: Selectively define ApplicationSet spec to drop argocd mod deps
2 parents b3c097c + 00a6d86 commit a5b5ba9

8 files changed

+196
-398
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ lint: golangci-bin ## Run configured golangci-lint and pre-commit.sh linters aga
143143

144144
envtest:
145145
mkdir -p $(ENVTEST_ASSETS_DIR)
146-
test -s $(ENVTEST_ASSETS_DIR)/setup-envtest || GOBIN=$(ENVTEST_ASSETS_DIR) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
146+
test -s $(ENVTEST_ASSETS_DIR)/setup-envtest || GOBIN=$(ENVTEST_ASSETS_DIR) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.17
147147

148148
test: generate manifests envtest ## Run tests.
149149
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./... -coverprofile cover.out $(GO_TEST_GINKGO_ARGS)

controllers/argocd/appset_hack.go

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// SPDX-FileCopyrightText: The RamenDR authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// This package is a workaround to not depend on argoCD go.mod, as that brings in the entire k8s as a dependency
5+
// causing several valid and invalid security warnings, and in general polluting the ramen module dependencies
6+
// as well. The issue this workaround package overcomes is: https://github.com/argoproj/argo-cd/issues/4055
7+
8+
// This version of the API is as per ArgoCD version:
9+
// https://github.com/argoproj/argo-cd/blob/release-2.10/pkg/apis/application/v1alpha1/applicationset_types.go
10+
11+
package argocdv1alpha1hack
12+
13+
import (
14+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15+
"k8s.io/apimachinery/pkg/runtime"
16+
"k8s.io/apimachinery/pkg/runtime/schema"
17+
)
18+
19+
// Below are just the bare minimum required fields that ramen uses for an ApplicationSet resource
20+
21+
type ApplicationSetList struct {
22+
metav1.TypeMeta `json:",inline"`
23+
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
24+
Items []ApplicationSet `json:"items" protobuf:"bytes,2,rep,name=items"`
25+
}
26+
27+
//nolint:maligned
28+
type ApplicationSet struct {
29+
metav1.TypeMeta `json:",inline"`
30+
metav1.ObjectMeta `json:"metadata" protobuf:"bytes,1,opt,name=metadata"`
31+
Spec ApplicationSetSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
32+
Status ApplicationSetStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
33+
}
34+
35+
type ApplicationSetSpec struct {
36+
Generators []ApplicationSetGenerator `json:"generators" protobuf:"bytes,2,name=generators"`
37+
Template ApplicationSetTemplate `json:"template" protobuf:"bytes,3,name=template"`
38+
}
39+
40+
type ApplicationSetGenerator struct {
41+
//nolint:lll
42+
ClusterDecisionResource *DuckTypeGenerator `json:"clusterDecisionResource,omitempty" protobuf:"bytes,5,name=clusterDecisionResource"`
43+
}
44+
45+
type DuckTypeGenerator struct {
46+
ConfigMapRef string `json:"configMapRef" protobuf:"bytes,1,name=configMapRef"`
47+
LabelSelector metav1.LabelSelector `json:"labelSelector,omitempty" protobuf:"bytes,4,name=labelSelector"`
48+
}
49+
50+
type ApplicationSetTemplate struct {
51+
ApplicationSetTemplateMeta `json:"metadata" protobuf:"bytes,1,name=metadata"`
52+
Spec ApplicationSpec `json:"spec" protobuf:"bytes,2,name=spec"`
53+
}
54+
55+
type ApplicationSetTemplateMeta struct{}
56+
57+
type ApplicationSpec struct {
58+
Destination ApplicationDestination `json:"destination" protobuf:"bytes,2,name=destination"`
59+
Project string `json:"project" protobuf:"bytes,3,name=project"`
60+
}
61+
62+
type ApplicationDestination struct {
63+
Namespace string `json:"namespace,omitempty" protobuf:"bytes,2,opt,name=namespace"`
64+
}
65+
66+
type ApplicationSetStatus struct{}
67+
68+
// DeepCopy### interfaces required to use ApplicationSet as a runtime.Object
69+
// Lifted from generated deep copy file for other resources
70+
71+
func (in *ApplicationSet) DeepCopyObject() runtime.Object {
72+
return in.DeepCopy()
73+
}
74+
75+
func (in *ApplicationSet) DeepCopy() *ApplicationSet {
76+
if in == nil {
77+
return nil
78+
}
79+
80+
out := new(ApplicationSet)
81+
82+
in.DeepCopyInto(out)
83+
84+
return out
85+
}
86+
87+
func (in *ApplicationSet) DeepCopyInto(out *ApplicationSet) {
88+
*out = *in
89+
out.TypeMeta = in.TypeMeta
90+
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
91+
out.Spec = in.Spec
92+
out.Status = in.Status
93+
}
94+
95+
// DeepCopy### interfaces required to use ApplicationSetList as a runtime.Object
96+
// Lifted from generated deep copy file for other resources
97+
func (in *ApplicationSetList) DeepCopyInto(out *ApplicationSetList) {
98+
*out = *in
99+
out.TypeMeta = in.TypeMeta
100+
101+
in.ListMeta.DeepCopyInto(&out.ListMeta)
102+
103+
if in.Items != nil {
104+
in, out := &in.Items, &out.Items
105+
*out = make([]ApplicationSet, len(*in))
106+
107+
for i := range *in {
108+
(*in)[i].DeepCopyInto(&(*out)[i])
109+
}
110+
}
111+
}
112+
113+
func (in *ApplicationSetList) DeepCopy() *ApplicationSetList {
114+
if in == nil {
115+
return nil
116+
}
117+
118+
out := new(ApplicationSetList)
119+
in.DeepCopyInto(out)
120+
121+
return out
122+
}
123+
124+
func (in *ApplicationSetList) DeepCopyObject() runtime.Object {
125+
c := in.DeepCopy()
126+
127+
return c
128+
}
129+
130+
// Schema registration helpers, with appropriate Group/Version/Kind values from the ArgoCD project
131+
132+
var (
133+
SchemeGroupVersion = schema.GroupVersion{Group: "argoproj.io", Version: "v1alpha1"}
134+
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
135+
AddToScheme = SchemeBuilder.AddToScheme
136+
)
137+
138+
func addKnownTypes(scheme *runtime.Scheme) error {
139+
scheme.AddKnownTypes(SchemeGroupVersion,
140+
&ApplicationSet{},
141+
&ApplicationSetList{},
142+
)
143+
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
144+
145+
return nil
146+
}

controllers/drplacementcontrol_controller.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ import (
3131
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3232
"sigs.k8s.io/controller-runtime/pkg/source"
3333

34-
argov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
3534
clrapiv1beta1 "github.com/open-cluster-management-io/api/cluster/v1beta1"
3635
rmn "github.com/ramendr/ramen/api/v1alpha1"
36+
argocdv1alpha1hack "github.com/ramendr/ramen/controllers/argocd"
3737
rmnutil "github.com/ramendr/ramen/controllers/util"
3838
"github.com/ramendr/ramen/controllers/volsync"
3939
)
@@ -1925,7 +1925,7 @@ func getApplicationDestinationNamespace(
19251925
log logr.Logger,
19261926
placement client.Object,
19271927
) (string, error) {
1928-
appSetList := argov1alpha1.ApplicationSetList{}
1928+
appSetList := argocdv1alpha1hack.ApplicationSetList{}
19291929
if err := client.List(context.TODO(), &appSetList); err != nil {
19301930
// If ApplicationSet CRD is not found in the API server,
19311931
// default to Subscription behavior, and return the placement namespace as the target VRG namespace

controllers/drplacementcontrol_controller_test.go

+9-15
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ import (
3030
ocmworkv1 "github.com/open-cluster-management/api/work/v1"
3131
viewv1beta1 "github.com/stolostron/multicloud-operators-foundation/pkg/apis/view/v1beta1"
3232

33-
argov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
3433
clrapiv1beta1 "github.com/open-cluster-management-io/api/cluster/v1beta1"
3534
rmn "github.com/ramendr/ramen/api/v1alpha1"
3635
"github.com/ramendr/ramen/controllers"
36+
argocdv1alpha1hack "github.com/ramendr/ramen/controllers/argocd"
3737
rmnutil "github.com/ramendr/ramen/controllers/util"
3838
plrv1 "github.com/stolostron/multicloud-operators-placementrule/pkg/apis/apps/v1"
3939
corev1 "k8s.io/api/core/v1"
@@ -141,30 +141,24 @@ var (
141141
},
142142
}
143143

144-
appSet = argov1alpha1.ApplicationSet{
144+
appSet = argocdv1alpha1hack.ApplicationSet{
145145
ObjectMeta: metav1.ObjectMeta{
146146
Name: "simple-appset",
147147
Namespace: DRPCNamespaceName,
148148
},
149-
Spec: argov1alpha1.ApplicationSetSpec{
150-
Template: argov1alpha1.ApplicationSetTemplate{
151-
ApplicationSetTemplateMeta: argov1alpha1.ApplicationSetTemplateMeta{Name: "{{cluster}}-guestbook"},
152-
Spec: argov1alpha1.ApplicationSpec{
149+
Spec: argocdv1alpha1hack.ApplicationSetSpec{
150+
Template: argocdv1alpha1hack.ApplicationSetTemplate{
151+
ApplicationSetTemplateMeta: argocdv1alpha1hack.ApplicationSetTemplateMeta{},
152+
Spec: argocdv1alpha1hack.ApplicationSpec{
153153
Project: "default",
154-
Source: &argov1alpha1.ApplicationSource{
155-
RepoURL: "https://github.com/argoproj/argocd-example-apps.git",
156-
TargetRevision: "HEAD",
157-
Path: "guestbook",
158-
},
159-
Destination: argov1alpha1.ApplicationDestination{
160-
Server: "{{url}}",
154+
Destination: argocdv1alpha1hack.ApplicationDestination{
161155
Namespace: ApplicationNamespace,
162156
},
163157
},
164158
},
165-
Generators: []argov1alpha1.ApplicationSetGenerator{
159+
Generators: []argocdv1alpha1hack.ApplicationSetGenerator{
166160
{
167-
ClusterDecisionResource: &argov1alpha1.DuckTypeGenerator{
161+
ClusterDecisionResource: &argocdv1alpha1hack.DuckTypeGenerator{
168162
LabelSelector: metav1.LabelSelector{
169163
MatchLabels: map[string]string{
170164
clrapiv1beta1.PlacementLabel: UserPlacementName,

controllers/suite_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ import (
4141
cpcv1 "open-cluster-management.io/config-policy-controller/api/v1"
4242
gppv1 "open-cluster-management.io/governance-policy-propagator/api/v1"
4343

44-
argov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
4544
clrapiv1beta1 "github.com/open-cluster-management-io/api/cluster/v1beta1"
4645
ramendrv1alpha1 "github.com/ramendr/ramen/api/v1alpha1"
4746
ramencontrollers "github.com/ramendr/ramen/controllers"
47+
argocdv1alpha1hack "github.com/ramendr/ramen/controllers/argocd"
4848
"github.com/ramendr/ramen/controllers/util"
4949
Recipe "github.com/ramendr/recipe/api/v1alpha1"
5050
velero "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
@@ -189,7 +189,7 @@ var _ = BeforeSuite(func() {
189189
err = clrapiv1beta1.AddToScheme(scheme.Scheme)
190190
Expect(err).NotTo(HaveOccurred())
191191

192-
err = argov1alpha1.AddToScheme(scheme.Scheme)
192+
err = argocdv1alpha1hack.AddToScheme(scheme.Scheme)
193193
Expect(err).NotTo(HaveOccurred())
194194
// +kubebuilder:scaffold:scheme
195195

0 commit comments

Comments
 (0)