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
LOG-3302: Update scc to desired #1806
Merged
openshift-merge-robot
merged 1 commit into
openshift:release-5.6
from
jcantrill:log3302b
Jan 5, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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,61 @@ | ||
package reconcile_test | ||
|
||
import ( | ||
"context" | ||
security "github.com/openshift/api/security/v1" | ||
"github.com/openshift/cluster-logging-operator/internal/reconcile" | ||
"github.com/openshift/cluster-logging-operator/internal/runtime" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/ginkgo/extensions/table" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("reconciling ", func() { | ||
|
||
var ( | ||
anSCC = &security.SecurityContextConstraints{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "SecurityContextConstraints", | ||
APIVersion: security.SchemeGroupVersion.String(), | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "bar", | ||
}, | ||
ReadOnlyRootFilesystem: true, | ||
} | ||
) | ||
|
||
var _ = DescribeTable("SCC", func(initial *security.SecurityContextConstraints, desired security.SecurityContextConstraints) { | ||
|
||
globalScheme := scheme.Scheme | ||
Expect(security.Install(globalScheme)).To(Succeed()) | ||
builder := fake.NewClientBuilder().WithScheme(globalScheme) | ||
if initial != nil { | ||
builder.WithRuntimeObjects(initial) | ||
} | ||
k8sClient := builder.Build() | ||
|
||
Expect(reconcile.SecurityContextConstraints(k8sClient, &desired)).To(Succeed(), "Expect no error reconciling secrets") | ||
|
||
key := client.ObjectKey{Name: desired.Name} | ||
act := &security.SecurityContextConstraints{} | ||
Expect(k8sClient.Get(context.TODO(), key, act)).To(Succeed(), "Exp. no error after reconciliation to try and verify") | ||
|
||
act.ResourceVersion = "" //dont care here | ||
desired.ResourceVersion = "" | ||
|
||
Expect(cmp.Diff(act, &desired)).To(BeEmpty(), "Exp. the spec to be the same") | ||
Expect(cmp.Diff(act, initial)).To(Not(BeEmpty()), "Exp. the spec to have been updated") | ||
}, | ||
Entry("when it does not exist should create it", nil, *anSCC), | ||
Entry("when spec is modified it should revert it", runtime.NewSCC("bar"), *anSCC), | ||
Entry("when spec is not modified it should do nothing", anSCC, *anSCC), | ||
) | ||
}) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we replace this block with
*to=*from
if all fields are to be copied?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SCCs don't have a "spec" field, they live off the root of the type. The only change we possibly could make is to use reflection over the fields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree. a
*to=*from
would copy more fields than we need.