-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always allow converting MySQL[AAD]Users back to v1alpha1 (#1393)
* Remove ignore entry for manager The output of `make manager` goes into bin/ which is already ignored. This entry was causing very confusing things to happen with directories called `manager` further down the directory tree. * Never error when converting v1alpha2 MySQLAADUser -> v1alpha1 (Unless JSON serialisation fails for some reason.) Instead we store the changed fields in an annotation and allow roundtripping that when converting in the other direction. * Never error when converting v1alpha2 MySQLUser -> v1alpha1 (Unless JSON serialisation fails for some reason.) Instead we store the changed fields in an annotation and allow roundtripping that when converting in the other direction. * Review feedback, thanks @matthchr * Comment out the replica server in the MySQL happy path test This is perpetually timing out for me at the moment, and testing manually shows that creation can take more than an hour.
- Loading branch information
1 parent
1e656f0
commit bfabead
Showing
7 changed files
with
396 additions
and
61 deletions.
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,53 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/pkg/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/conversion" | ||
) | ||
|
||
const conversionStashAnnotation = "azure.microsoft.com/convert-stash" | ||
|
||
// getStashedAnnotation unmarshals the convert-stash annotation value | ||
// into the target pointer, if the annotation is present. It returns | ||
// whether the annotation was present, and any error from unmarshalling. | ||
func getStashedAnnotation(meta metav1.ObjectMeta, target interface{}) (bool, error) { | ||
if _, err := conversion.EnforcePtr(target); err != nil { | ||
return false, errors.Errorf("getStashedAnnotation target must be a pointer, not %T", target) | ||
} | ||
if meta.Annotations == nil { | ||
return false, nil | ||
} | ||
value, found := meta.Annotations[conversionStashAnnotation] | ||
if !found { | ||
return false, nil | ||
} | ||
if err := json.Unmarshal([]byte(value), target); err != nil { | ||
return false, errors.Wrap(err, "decoding stashed fields") | ||
} | ||
return true, nil | ||
} | ||
|
||
func setStashedAnnotation(meta *metav1.ObjectMeta, stashValues interface{}) error { | ||
if meta.Annotations == nil { | ||
meta.Annotations = make(map[string]string) | ||
} | ||
encoded, err := json.Marshal(stashValues) | ||
if err != nil { | ||
return errors.Wrap(err, "encoding stashed fields") | ||
} | ||
meta.Annotations[conversionStashAnnotation] = string(encoded) | ||
return nil | ||
} | ||
|
||
func clearStashedAnnotation(meta *metav1.ObjectMeta) { | ||
delete(meta.Annotations, conversionStashAnnotation) | ||
if len(meta.Annotations) == 0 { | ||
meta.Annotations = nil | ||
} | ||
} |
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
Oops, something went wrong.