Skip to content

Commit

Permalink
Merge pull request #516 from crossplane/backport-512-to-release-1.13
Browse files Browse the repository at this point in the history
[Backport release-1.13] Cleanup deprecated code that are no longer used
  • Loading branch information
turkenh authored Aug 14, 2023
2 parents 359d539 + 98d93a5 commit 9cfe1db
Show file tree
Hide file tree
Showing 14 changed files with 0 additions and 1,151 deletions.
22 changes: 0 additions & 22 deletions pkg/fieldpath/paved.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,28 +321,6 @@ func (p *Paved) GetBool(path string) (bool, error) {
return b, nil
}

// NOTE(muvaf): If there is no CRD, unstructured.Unstructured reads numbers as
// float64. However, in practice, use of float64 is discouraged and when you fetch
// an instance of a CRD whose number fields are int64, you'll get int64. So,
// it's not really possible to test this without an api-server but that's the
// actual behavior.

// GetNumber value of the supplied field path.
// Deprecated: Use of float64 is discouraged. Please use GetInteger.
// See https://github.com/kubernetes/community/blob/c9ae475/contributors/devel/sig-architecture/api-conventions.md#primitive-types
func (p *Paved) GetNumber(path string) (float64, error) {
v, err := p.GetValue(path)
if err != nil {
return 0, err
}

f, ok := v.(float64)
if !ok {
return 0, errors.Errorf("%s: not a (float64) number", path)
}
return f, nil
}

// GetInteger value of the supplied field path.
func (p *Paved) GetInteger(path string) (int64, error) {
v, err := p.GetValue(path)
Expand Down
53 changes: 0 additions & 53 deletions pkg/fieldpath/paved_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,59 +484,6 @@ func TestGetBool(t *testing.T) {
}
}

func TestGetNumber(t *testing.T) {
type want struct {
value float64
err error
}
cases := map[string]struct {
reason string
path string
data []byte
want want
}{
"MetadataVersion": {
reason: "Requesting a number field should work",
path: "metadata.version",
data: []byte(`{"metadata":{"version":2.0}}`),
want: want{
value: 2,
},
},
"MalformedPath": {
reason: "Requesting an invalid field path should fail",
path: "spec[]",
want: want{
err: errors.Wrap(errors.New("unexpected ']' at position 5"), "cannot parse path \"spec[]\""),
},
},
"NotANumber": {
reason: "Requesting an non-number field path should fail",
path: "metadata.name",
data: []byte(`{"metadata":{"name":"cool"}}`),
want: want{
err: errors.New("metadata.name: not a (float64) number"),
},
},
}

for name, tc := range cases {
t.Run(name, func(t *testing.T) {
in := make(map[string]any)
_ = json.Unmarshal(tc.data, &in)
p := Pave(in)

got, err := p.GetNumber(tc.path)
if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" {
t.Fatalf("\np.GetNumber(%s): %s: -want error, +got error:\n%s", tc.path, tc.reason, diff)
}
if diff := cmp.Diff(tc.want.value, got); diff != "" {
t.Errorf("\np.GetNumber(%s): %s: -want, +got:\n%s", tc.path, tc.reason, diff)
}
})
}
}

func TestGetInteger(t *testing.T) {
type want struct {
value int64
Expand Down
74 changes: 0 additions & 74 deletions pkg/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ limitations under the License.
package meta

import (
"fmt"
"hash/fnv"
"strings"
"time"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -66,17 +63,6 @@ const (
AnnotationKeyReconciliationPaused = "crossplane.io/paused"
)

// Supported resources with all of these annotations will be fully or partially
// propagated to the named resource of the same kind, assuming it exists and
// consents to propagation.
const (
AnnotationKeyPropagateToPrefix = "to.propagate.crossplane.io/"

// Deprecated: This functionality will be removed soon.
AnnotationKeyPropagateFromNamespace = "from.propagate.crossplane.io/namespace"
AnnotationKeyPropagateFromName = "from.propagate.crossplane.io/name"
)

// ReferenceTo returns an object reference to the supplied object, presumed to
// be of the supplied group, version, and kind.
// Deprecated: use a more specific reference type, such as TypedReference or
Expand Down Expand Up @@ -361,66 +347,6 @@ func ExternalCreateSucceededDuring(o metav1.Object, d time.Duration) bool {
return time.Since(t) < d
}

// AllowPropagation from one object to another by adding consenting annotations
// to both.
// Deprecated: This functionality will be removed soon.
func AllowPropagation(from, to metav1.Object) {
AddAnnotations(to, map[string]string{
AnnotationKeyPropagateFromNamespace: from.GetNamespace(),
AnnotationKeyPropagateFromName: from.GetName(),
})

AddAnnotations(from, map[string]string{
AnnotationKeyPropagateTo(to): to.GetNamespace() + "/" + to.GetName(),
})
}

// AnnotationKeyPropagateTo returns an annotation key whose presence indicates
// that the annotated object consents to propagation from the supplied object.
// The annotation name (which follows the prefix) can be anything that doesn't
// collide with another annotation. to.propagation.crossplane.io/example would
// be valid. This function uses a hash of the supplied object's namespace and
// name in order to avoid collisions and keep the suffix relatively short.
func AnnotationKeyPropagateTo(o metav1.Object) string {
// Writing to a hash never returns an error.
h := fnv.New32a()
h.Write([]byte(o.GetNamespace()))
h.Write([]byte(o.GetName()))
return fmt.Sprintf("%s%x", AnnotationKeyPropagateToPrefix, h.Sum32())
}

// AllowsPropagationFrom returns the NamespacedName of the object the supplied
// object should be propagated from.
func AllowsPropagationFrom(to metav1.Object) types.NamespacedName {
return types.NamespacedName{
Namespace: to.GetAnnotations()[AnnotationKeyPropagateFromNamespace],
Name: to.GetAnnotations()[AnnotationKeyPropagateFromName],
}
}

// AllowsPropagationTo returns the set of NamespacedNames that the supplied
// object may be propagated to.
func AllowsPropagationTo(from metav1.Object) map[types.NamespacedName]bool {
to := make(map[types.NamespacedName]bool)

for k, v := range from.GetAnnotations() {
nn := strings.Split(v, "/")
switch {
case !strings.HasPrefix(k, AnnotationKeyPropagateToPrefix):
continue
case len(nn) != 2:
continue
case nn[0] == "":
continue
case nn[1] == "":
continue
}
to[types.NamespacedName{Namespace: nn[0], Name: nn[1]}] = true
}

return to
}

// IsPaused returns true if the object has the AnnotationKeyReconciliationPaused
// annotation set to `true`.
func IsPaused(o metav1.Object) bool {
Expand Down
143 changes: 0 additions & 143 deletions pkg/meta/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package meta

import (
"fmt"
"hash/fnv"
"testing"
"time"

Expand Down Expand Up @@ -1181,147 +1179,6 @@ func TestExternalCreateIncomplete(t *testing.T) {
}
}

func TestAllowPropagation(t *testing.T) {
fromns := "from-namespace"
from := "from-name"
tons := "to-namespace"
to := "to-name"

tohash := func() string {
h := fnv.New32a()
h.Write([]byte(tons))
h.Write([]byte(to))
return fmt.Sprintf("%x", h.Sum32())
}()

type args struct {
from metav1.Object
to metav1.Object
}
type want struct {
from metav1.Object
to metav1.Object
}

cases := map[string]struct {
args args
want want
}{
"Successful": {
args: args{
from: &corev1.Pod{ObjectMeta: metav1.ObjectMeta{
Namespace: fromns,
Name: from,
Annotations: map[string]string{
"existing": "annotation",
},
}},
to: &corev1.Pod{ObjectMeta: metav1.ObjectMeta{
Namespace: tons,
Name: to,
Annotations: map[string]string{
"existing": "annotation",
},
}},
},
want: want{
from: &corev1.Pod{ObjectMeta: metav1.ObjectMeta{
Namespace: fromns,
Name: from,
Annotations: map[string]string{
"existing": "annotation",
AnnotationKeyPropagateToPrefix + tohash: tons + "/" + to,
},
}},
to: &corev1.Pod{ObjectMeta: metav1.ObjectMeta{
Namespace: tons,
Name: to,
Annotations: map[string]string{
"existing": "annotation",
AnnotationKeyPropagateFromNamespace: fromns,
AnnotationKeyPropagateFromName: from,
},
}},
},
},
}

for name, tc := range cases {
t.Run(name, func(t *testing.T) {
AllowPropagation(tc.args.from, tc.args.to)
if diff := cmp.Diff(tc.want.from, tc.args.from); diff != "" {
t.Errorf("AllowPropagation(...): -want from, +got from\n%s", diff)
}
if diff := cmp.Diff(tc.want.to, tc.args.to); diff != "" {
t.Errorf("AllowPropagation(...): -want to, +got to\n%s", diff)
}
})
}
}

func TestAllowsPropagationFrom(t *testing.T) {
ns := "coolns"
name := "coolname"

cases := map[string]struct {
to metav1.Object
want types.NamespacedName
}{
"Successful": {
to: &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{
AnnotationKeyPropagateFromNamespace: ns,
AnnotationKeyPropagateFromName: name,
}}},
want: types.NamespacedName{Namespace: ns, Name: name},
},
}

for name, tc := range cases {
t.Run(name, func(t *testing.T) {
got := AllowsPropagationFrom(tc.to)
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("AllowsPropagationFrom(...): -want, +got\n%s", diff)
}
})
}
}

func TestAllowsPropagationTo(t *testing.T) {
nsA := "coolns"
nameA := "coolname"
nsB := "coolerns"
nameB := "coolername"

cases := map[string]struct {
from metav1.Object
want map[types.NamespacedName]bool
}{
"Successful": {
from: &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{
"existing": "annotation",
AnnotationKeyPropagateToPrefix + "missingslash": "wat",
AnnotationKeyPropagateToPrefix + "missingname": "wat/",
AnnotationKeyPropagateToPrefix + "missingnamespace": "/wat",
AnnotationKeyPropagateToPrefix + "a": nsA + "/" + nameA,
AnnotationKeyPropagateToPrefix + "b": nsB + "/" + nameB,
}}},
want: map[types.NamespacedName]bool{
{Namespace: nsA, Name: nameA}: true,
{Namespace: nsB, Name: nameB}: true,
},
},
}

for name, tc := range cases {
t.Run(name, func(t *testing.T) {
got := AllowsPropagationTo(tc.from)
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("AllowsPropagationTo(...): -want, +got\n%s", diff)
}
})
}
}

func TestIsPaused(t *testing.T) {
cases := map[string]struct {
o metav1.Object
Expand Down
30 changes: 0 additions & 30 deletions pkg/ratelimiter/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/ratelimiter"
)

const (
// DefaultProviderRPS is the recommended default average requeues per
// second tolerated by a Crossplane provider.
//
// Deprecated: Use a flag
DefaultProviderRPS = 1
)

// NewGlobal returns a token bucket rate limiter meant for limiting the number
// of average total requeues per second for all controllers registered with a
// controller manager. The bucket size (i.e. allowed burst) is rps * 10.
Expand All @@ -48,28 +40,6 @@ func NewController() ratelimiter.RateLimiter {
return workqueue.NewItemExponentialFailureRateLimiter(1*time.Second, 60*time.Second)
}

// NewDefaultProviderRateLimiter returns a token bucket rate limiter meant for
// limiting the number of average total requeues per second for all controllers
// registered with a controller manager. The bucket size is a linear function of
// the requeues per second.
//
// Deprecated: Use NewGlobal.
func NewDefaultProviderRateLimiter(rps int) *workqueue.BucketRateLimiter {
return NewGlobal(rps)
}

// NewDefaultManagedRateLimiter returns a rate limiter that takes the maximum
// delay between the passed provider and a per-item exponential backoff limiter.
// The exponential backoff limiter has a base delay of 1s and a maximum of 60s.
//
// Deprecated: Use NewController.
func NewDefaultManagedRateLimiter(provider ratelimiter.RateLimiter) ratelimiter.RateLimiter {
return workqueue.NewMaxOfRateLimiter(
workqueue.NewItemExponentialFailureRateLimiter(1*time.Second, 60*time.Second),
provider,
)
}

// LimitRESTConfig returns a copy of the supplied REST config with rate limits
// derived from the supplied rate of reconciles per second.
func LimitRESTConfig(cfg *rest.Config, rps int) *rest.Config {
Expand Down
Loading

0 comments on commit 9cfe1db

Please sign in to comment.