misc: `fake.NewFakeClientWithScheme` deprecation
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
This commit is contained in:
parent
ca17176cd3
commit
61bf78379d
|
|
@ -178,15 +178,13 @@ func TestHelmReleaseReconciler_reconcileChart(t *testing.T) {
|
||||||
g.Expect(v2.AddToScheme(scheme.Scheme)).To(Succeed())
|
g.Expect(v2.AddToScheme(scheme.Scheme)).To(Succeed())
|
||||||
g.Expect(sourcev1.AddToScheme(scheme.Scheme)).To(Succeed())
|
g.Expect(sourcev1.AddToScheme(scheme.Scheme)).To(Succeed())
|
||||||
|
|
||||||
var c client.Client
|
c := fake.NewClientBuilder().WithScheme(scheme.Scheme)
|
||||||
if tt.hc != nil {
|
if tt.hc != nil {
|
||||||
c = fake.NewFakeClientWithScheme(scheme.Scheme, tt.hc)
|
c.WithObjects(tt.hc)
|
||||||
} else {
|
|
||||||
c = fake.NewFakeClientWithScheme(scheme.Scheme)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r := &HelmReleaseReconciler{
|
r := &HelmReleaseReconciler{
|
||||||
Client: c,
|
Client: c.Build(),
|
||||||
NoCrossNamespaceRef: tt.noCrossNamspaceRef,
|
NoCrossNamespaceRef: tt.noCrossNamspaceRef,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -203,7 +201,7 @@ func TestHelmReleaseReconciler_reconcileChart(t *testing.T) {
|
||||||
|
|
||||||
if tt.expectGC {
|
if tt.expectGC {
|
||||||
objKey := client.ObjectKeyFromObject(tt.hc)
|
objKey := client.ObjectKeyFromObject(tt.hc)
|
||||||
err = c.Get(context.TODO(), objKey, tt.hc.DeepCopy())
|
err = r.Get(context.TODO(), objKey, tt.hc.DeepCopy())
|
||||||
g.Expect(apierrors.IsNotFound(err)).To(BeTrue())
|
g.Expect(apierrors.IsNotFound(err)).To(BeTrue())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -259,15 +257,13 @@ func TestHelmReleaseReconciler_deleteHelmChart(t *testing.T) {
|
||||||
g.Expect(v2.AddToScheme(scheme.Scheme)).To(Succeed())
|
g.Expect(v2.AddToScheme(scheme.Scheme)).To(Succeed())
|
||||||
g.Expect(sourcev1.AddToScheme(scheme.Scheme)).To(Succeed())
|
g.Expect(sourcev1.AddToScheme(scheme.Scheme)).To(Succeed())
|
||||||
|
|
||||||
var c client.Client
|
c := fake.NewClientBuilder().WithScheme(scheme.Scheme)
|
||||||
if tt.hc != nil {
|
if tt.hc != nil {
|
||||||
c = fake.NewFakeClientWithScheme(scheme.Scheme, tt.hc)
|
c.WithObjects(tt.hc)
|
||||||
} else {
|
|
||||||
c = fake.NewFakeClientWithScheme(scheme.Scheme)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r := &HelmReleaseReconciler{
|
r := &HelmReleaseReconciler{
|
||||||
Client: c,
|
Client: c.Build(),
|
||||||
}
|
}
|
||||||
|
|
||||||
err := r.deleteHelmChart(context.TODO(), tt.hr)
|
err := r.deleteHelmChart(context.TODO(), tt.hr)
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import (
|
||||||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
|
|
@ -122,7 +123,7 @@ other: values
|
||||||
// v2.ValuesReference. Therefore a static value here suffices, and instead we just
|
// v2.ValuesReference. Therefore a static value here suffices, and instead we just
|
||||||
// play with the objects presence/absence.
|
// play with the objects presence/absence.
|
||||||
objectName := "values"
|
objectName := "values"
|
||||||
resources := []runtime.Object{}
|
var resources []client.Object
|
||||||
|
|
||||||
if createObject {
|
if createObject {
|
||||||
resources = append(resources,
|
resources = append(resources,
|
||||||
|
|
@ -146,7 +147,7 @@ other: values
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
c := fake.NewFakeClientWithScheme(scheme, resources...)
|
c := fake.NewClientBuilder().WithScheme(scheme).WithObjects(resources...).Build()
|
||||||
r := &HelmReleaseReconciler{Client: c}
|
r := &HelmReleaseReconciler{Client: c}
|
||||||
var values *apiextensionsv1.JSON
|
var values *apiextensionsv1.JSON
|
||||||
if hrValues != "" {
|
if hrValues != "" {
|
||||||
|
|
@ -221,13 +222,13 @@ other: values
|
||||||
hc.ObjectMeta.Name = hr.GetHelmChartName()
|
hc.ObjectMeta.Name = hr.GetHelmChartName()
|
||||||
hc.ObjectMeta.Namespace = hr.Spec.Chart.GetNamespace(hr.Namespace)
|
hc.ObjectMeta.Namespace = hr.Spec.Chart.GetNamespace(hr.Namespace)
|
||||||
|
|
||||||
resources := []runtime.Object{
|
resources := []client.Object{
|
||||||
valuesConfigMap("values", map[string]string{valuesKey: configData}),
|
valuesConfigMap("values", map[string]string{valuesKey: configData}),
|
||||||
valuesSecret("values", map[string][]byte{valuesKey: secretData}),
|
valuesSecret("values", map[string][]byte{valuesKey: secretData}),
|
||||||
&hc,
|
&hc,
|
||||||
}
|
}
|
||||||
|
|
||||||
c := fake.NewFakeClientWithScheme(scheme, resources...)
|
c := fake.NewClientBuilder().WithScheme(scheme).WithObjects(resources...).Build()
|
||||||
r := &HelmReleaseReconciler{
|
r := &HelmReleaseReconciler{
|
||||||
Client: c,
|
Client: c,
|
||||||
EventRecorder: &DummyRecorder{},
|
EventRecorder: &DummyRecorder{},
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ func TestHelmReleaseReconciler_composeValues(t *testing.T) {
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
resources []runtime.Object
|
resources []client.Object
|
||||||
references []v2.ValuesReference
|
references []v2.ValuesReference
|
||||||
values string
|
values string
|
||||||
want chartutil.Values
|
want chartutil.Values
|
||||||
|
|
@ -51,7 +51,7 @@ func TestHelmReleaseReconciler_composeValues(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "merges",
|
name: "merges",
|
||||||
resources: []runtime.Object{
|
resources: []client.Object{
|
||||||
valuesConfigMap("values", map[string]string{
|
valuesConfigMap("values", map[string]string{
|
||||||
"values.yaml": `flat: value
|
"values.yaml": `flat: value
|
||||||
nested:
|
nested:
|
||||||
|
|
@ -88,7 +88,7 @@ other: values
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "target path",
|
name: "target path",
|
||||||
resources: []runtime.Object{
|
resources: []client.Object{
|
||||||
valuesSecret("values", map[string][]byte{"single": []byte("value")}),
|
valuesSecret("values", map[string][]byte{"single": []byte("value")}),
|
||||||
},
|
},
|
||||||
references: []v2.ValuesReference{
|
references: []v2.ValuesReference{
|
||||||
|
|
@ -111,7 +111,7 @@ other: values
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "target path with boolean value",
|
name: "target path with boolean value",
|
||||||
resources: []runtime.Object{
|
resources: []client.Object{
|
||||||
valuesSecret("values", map[string][]byte{"single": []byte("true")}),
|
valuesSecret("values", map[string][]byte{"single": []byte("true")}),
|
||||||
},
|
},
|
||||||
references: []v2.ValuesReference{
|
references: []v2.ValuesReference{
|
||||||
|
|
@ -134,7 +134,7 @@ other: values
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "target path with set-string behavior",
|
name: "target path with set-string behavior",
|
||||||
resources: []runtime.Object{
|
resources: []client.Object{
|
||||||
valuesSecret("values", map[string][]byte{"single": []byte("\"true\"")}),
|
valuesSecret("values", map[string][]byte{"single": []byte("\"true\"")}),
|
||||||
},
|
},
|
||||||
references: []v2.ValuesReference{
|
references: []v2.ValuesReference{
|
||||||
|
|
@ -201,7 +201,7 @@ other: values
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "missing secret key",
|
name: "missing secret key",
|
||||||
resources: []runtime.Object{
|
resources: []client.Object{
|
||||||
valuesSecret("values", nil),
|
valuesSecret("values", nil),
|
||||||
},
|
},
|
||||||
references: []v2.ValuesReference{
|
references: []v2.ValuesReference{
|
||||||
|
|
@ -215,7 +215,7 @@ other: values
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "missing config map key",
|
name: "missing config map key",
|
||||||
resources: []runtime.Object{
|
resources: []client.Object{
|
||||||
valuesConfigMap("values", nil),
|
valuesConfigMap("values", nil),
|
||||||
},
|
},
|
||||||
references: []v2.ValuesReference{
|
references: []v2.ValuesReference{
|
||||||
|
|
@ -238,7 +238,7 @@ other: values
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid values",
|
name: "invalid values",
|
||||||
resources: []runtime.Object{
|
resources: []client.Object{
|
||||||
valuesConfigMap("values", map[string]string{
|
valuesConfigMap("values", map[string]string{
|
||||||
"values.yaml": `
|
"values.yaml": `
|
||||||
invalid`,
|
invalid`,
|
||||||
|
|
@ -256,7 +256,7 @@ invalid`,
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
c := fake.NewFakeClientWithScheme(scheme, tt.resources...)
|
c := fake.NewClientBuilder().WithScheme(scheme).WithObjects(tt.resources...).Build()
|
||||||
r := &HelmReleaseReconciler{Client: c}
|
r := &HelmReleaseReconciler{Client: c}
|
||||||
var values *apiextensionsv1.JSON
|
var values *apiextensionsv1.JSON
|
||||||
if tt.values != "" {
|
if tt.values != "" {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue