Skip to content
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

[release-4.1] Bug 1734622: resourceapply: don't log secret data #472

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion pkg/operator/resource/resourceapply/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ func ApplyConfigMap(client coreclientv1.ConfigMapsGetter, recorder events.Record

// ApplySecret merges objectmeta, requires data
func ApplySecret(client coreclientv1.SecretsGetter, recorder events.Recorder, required *corev1.Secret) (*corev1.Secret, bool, error) {
if len(required.StringData) > 0 {
return nil, false, fmt.Errorf("Secret.stringData is not supported")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not?

Copy link
Contributor Author

@sttts sttts Jul 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's normalized by the server to Data, and we would have to add that normalization here before the DeepEqual. Not impossible, just not done.

}

existing, err := client.Secrets(required.Namespace).Get(required.Name, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
actual, err := client.Secrets(required.Namespace).Create(required)
Expand All @@ -210,14 +214,31 @@ func ApplySecret(client coreclientv1.SecretsGetter, recorder events.Recorder, re
existingCopy := existing.DeepCopy()

resourcemerge.EnsureObjectMeta(modified, &existingCopy.ObjectMeta, required.ObjectMeta)

dataSame := equality.Semantic.DeepEqual(existingCopy.Data, required.Data)
if dataSame && !*modified {
return existingCopy, false, nil
}
existingCopy.Data = required.Data

if klog.V(4) {
klog.Infof("Secret %q changes: %v", required.Namespace+"/"+required.Name, JSONPatch(existing, required))
safeRequired := required.DeepCopy()
safeExisting := existing.DeepCopy()

for s := range safeExisting.Data {
safeExisting.Data[s] = []byte("OLD")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we want OLD, NEW and MODIFIED as the states to track?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean with 3 states? We only have two.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ic what you mean. But note that we create a patch below. We cannot have OLD and NEW for all fields, only those which changed.

}
for s := range safeRequired.Data {
if _, preexisting := existing.Data[s]; !preexisting {
safeRequired.Data[s] = []byte("NEW")
} else if !equality.Semantic.DeepEqual(existing.Data[s], safeRequired.Data[s]) {
safeRequired.Data[s] = []byte("MODIFIED")
} else {
safeRequired.Data[s] = []byte("OLD")
}
}

klog.Infof("Secret %q changes: %v", required.Namespace+"/"+required.Name, JSONPatch(safeExisting, safeRequired))
}
actual, err := client.Secrets(required.Namespace).Update(existingCopy)

Expand Down