diff --git a/api/v1alpha1/conversion_stash.go b/api/v1alpha1/conversion_stash.go index 0b01322fc85..a2194bedeb7 100644 --- a/api/v1alpha1/conversion_stash.go +++ b/api/v1alpha1/conversion_stash.go @@ -8,11 +8,18 @@ import ( "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 } diff --git a/api/v1alpha1/mysqlaaduser_conversion.go b/api/v1alpha1/mysqlaaduser_conversion.go index a5a4d101731..b798ca26e50 100644 --- a/api/v1alpha1/mysqlaaduser_conversion.go +++ b/api/v1alpha1/mysqlaaduser_conversion.go @@ -91,6 +91,8 @@ func (dst *MySQLAADUser) ConvertFrom(srcRaw conversion.Hub) error { for dbName := range src.Spec.DatabaseRoles { dbNames = append(dbNames, dbName) } + // Sorting the list of names for testing (and so that a client + // gets a consistent value back for a resource). sort.Strings(dbNames) var ( dbName string diff --git a/api/v1alpha1/mysqluser_conversion.go b/api/v1alpha1/mysqluser_conversion.go index 4644a873999..5a2c3868785 100644 --- a/api/v1alpha1/mysqluser_conversion.go +++ b/api/v1alpha1/mysqluser_conversion.go @@ -95,6 +95,8 @@ func (dst *MySQLUser) ConvertFrom(srcRaw conversion.Hub) error { for dbName := range src.Spec.DatabaseRoles { dbNames = append(dbNames, dbName) } + // Sorting the list of names for testing (and so that a client + // gets a consistent value back for a resource). sort.Strings(dbNames) var ( dbName string