Skip to content

Commit

Permalink
🐛 Enable spec syncer for agent (stolostron#887)
Browse files Browse the repository at this point in the history
* Enable spec syncer for agent

Signed-off-by: myan <[email protected]>

* fmt

Signed-off-by: myan <[email protected]>

---------

Signed-off-by: myan <[email protected]>
  • Loading branch information
yanmxa authored Apr 12, 2024
1 parent 374215a commit 4c514b4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ func enableCleanUpFinalizer(obj client.Object) bool {
func cleanObject(object client.Object) {
object.SetManagedFields(nil)
object.SetFinalizers(nil)
object.SetGeneration(0)
object.SetOwnerReferences(nil)
object.SetSelfLink("")
// object.SetClusterName("")
Expand Down
36 changes: 36 additions & 0 deletions agent/pkg/status/controller/policies/local_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,44 @@ var _ = Describe("LocalPolicyEmitters", Ordered, func() {
evt := <-consumer.EventChan()
fmt.Println(evt)
if evt.Type() != string(enum.LocalPolicySpecType) {
policy := &policyv1.Policy{}
err := evt.DataAs(policy)
if err != nil {
return err
}
if !policy.Spec.Disabled {
return fmt.Errorf("policy should be disabled")
}
return fmt.Errorf("want %v, got %v", string(enum.LocalPolicySpecType), evt.Type())
}
fmt.Println("============================ create policy -> policy spec event")
return nil
}, 5*time.Second, 100*time.Millisecond).Should(Succeed())

By("Update the root policy")
err := kubeClient.Get(ctx, client.ObjectKeyFromObject(localRootPolicy), localRootPolicy)
Expect(err).Should(Succeed())

localRootPolicy.Spec.Disabled = false
err = kubeClient.Update(ctx, localRootPolicy)
Expect(err).Should(Succeed())

By("Check the local policy spec can be read from cloudevents consumer")
Eventually(func() error {
evt := <-consumer.EventChan()
fmt.Println(evt)
if evt.Type() != string(enum.LocalPolicySpecType) {
policy := &policyv1.Policy{}
err := evt.DataAs(policy)
if err != nil {
return err
}
if policy.Spec.Disabled {
return fmt.Errorf("policy should be enabled")
}
return fmt.Errorf("want %v, got %v", string(enum.LocalPolicySpecType), evt.Type())
}
fmt.Println("============================ update policy -> policy spec event")
return nil
}, 5*time.Second, 100*time.Millisecond).Should(Succeed())
})
Expand Down

0 comments on commit 4c514b4

Please sign in to comment.