-
Notifications
You must be signed in to change notification settings - Fork 164
Generic sync/suspend/inventory listing #4096
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e9e208a
Refactor /inventory code to expose some helpers
foot 13a9629
Move the loops, docs a bit
foot 10d0da2
Handle unstructured reconcilation of "ks-like" resoureces
foot 6a3dc48
Use correc json field names for inv structs
foot 5bc52cf
Adds support for syncing/suspending/inventorying generic resources
foot 78b576e
Add missing test file oops
foot fc3a210
Revert refactor in other branch for now
foot afe5773
Share a little bit more code
foot a9c9e4f
Fixes inv parsing
foot 85cc01b
Fixes some static lint checks
foot 7f5395d
Fixes another lint warning, don't shadow `copy`
foot 5b1f4a6
Convert the entire inventory from unstructured
foot 8a3ec8c
Improves test to check AsClientObject retrieval
foot aa84121
Review feedback,
foot 7810415
Modernise our multi-error handling, golang can do it now
foot 0e3452d
Merge branch 'main' into generic-sync-suspend-inv
foot fa338e3
Expose `useListEvents` via npm module
foot 7eedc62
Improve error messages and tidy up error assertions in tests
foot 67a8803
Merge branch 'main' into generic-sync-suspend-inv
foot dfadf27
Merge branch 'main' into generic-sync-suspend-inv
foot 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| package fluxsync | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
| v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
| ) | ||
|
|
||
| func TestGetLastHandledReconcileRequest(t *testing.T) { | ||
| g := NewGomegaWithT(t) | ||
|
|
||
| obj := &UnstructuredAdapter{ | ||
| Unstructured: &unstructured.Unstructured{ | ||
| Object: map[string]interface{}{ | ||
| "status": map[string]interface{}{ | ||
| "lastHandledReconcileAt": "2023-10-20T10:10:10Z", | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| expected := "2023-10-20T10:10:10Z" | ||
| got := obj.GetLastHandledReconcileRequest() | ||
| g.Expect(got).To(Equal(expected)) | ||
| } | ||
|
|
||
| func TestGetConditions(t *testing.T) { | ||
| g := NewGomegaWithT(t) | ||
|
|
||
| condition := v1.Condition{ | ||
| Type: "Ready", | ||
| Status: "True", | ||
| } | ||
| unstructuredCondition, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(&condition) | ||
|
|
||
| obj := &UnstructuredAdapter{ | ||
| Unstructured: &unstructured.Unstructured{ | ||
| Object: map[string]interface{}{ | ||
| "status": map[string]interface{}{ | ||
| "conditions": []interface{}{unstructuredCondition}, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| conditions := obj.GetConditions() | ||
| g.Expect(conditions).To(HaveLen(1)) | ||
| g.Expect(conditions[0].Type).To(Equal(condition.Type)) | ||
| g.Expect(conditions[0].Status).To(Equal(condition.Status)) | ||
| } | ||
|
|
||
| func TestSetSuspended(t *testing.T) { | ||
| g := NewGomegaWithT(t) | ||
|
|
||
| obj := &UnstructuredAdapter{ | ||
| Unstructured: &unstructured.Unstructured{ | ||
| Object: make(map[string]interface{}), | ||
| }, | ||
| } | ||
|
|
||
| err := obj.SetSuspended(true) | ||
| g.Expect(err).NotTo(HaveOccurred()) | ||
| suspend, _, _ := unstructured.NestedBool(obj.Object, "spec", "suspend") | ||
| g.Expect(suspend).To(BeTrue()) | ||
| } | ||
|
|
||
| func TestDeepCopyClientObject(t *testing.T) { | ||
| g := NewGomegaWithT(t) | ||
|
|
||
| obj := &UnstructuredAdapter{ | ||
| Unstructured: &unstructured.Unstructured{ | ||
| Object: map[string]interface{}{"key": "value"}, | ||
| }, | ||
| } | ||
|
|
||
| objCopy := obj.DeepCopyClientObject().(*unstructured.Unstructured) | ||
| g.Expect(objCopy.Object).To(Equal(obj.Object)) | ||
| g.Expect(objCopy).ToNot(BeIdenticalTo(obj)) | ||
| } | ||
|
|
||
| func TestAsClientObjectCompatibilityWithTestClient(t *testing.T) { | ||
| g := NewGomegaWithT(t) | ||
|
|
||
| scheme := runtime.NewScheme() | ||
|
|
||
| cl := fake.NewClientBuilder().WithScheme(scheme).Build() | ||
|
|
||
| obj := &UnstructuredAdapter{ | ||
| Unstructured: &unstructured.Unstructured{ | ||
| Object: map[string]interface{}{ | ||
| "apiVersion": "v1", | ||
| "kind": "ConfigMap", | ||
| "metadata": map[string]interface{}{ | ||
| "name": "test-cm", | ||
| "namespace": "default", | ||
| }, | ||
| "data": map[string]interface{}{"key": "value"}, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| err := cl.Create(context.TODO(), obj.AsClientObject()) | ||
| g.Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| retrieved := &UnstructuredAdapter{ | ||
| Unstructured: &unstructured.Unstructured{ | ||
| Object: map[string]interface{}{ | ||
| "apiVersion": "v1", | ||
| "kind": "ConfigMap", | ||
| }, | ||
| }, | ||
| } | ||
| err = cl.Get(context.TODO(), client.ObjectKey{Namespace: "default", Name: "test-cm"}, retrieved.AsClientObject()) | ||
| g.Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| // check the data key | ||
| data, _, _ := unstructured.NestedStringMap(retrieved.Object, "data") | ||
| g.Expect(data).To(Equal(map[string]string{"key": "value"})) | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.