Skip to content

Commit 7b2ad93

Browse files
committed
remove untested identity and reference
1 parent b82c40d commit 7b2ad93

3 files changed

Lines changed: 0 additions & 134 deletions

File tree

apis/tags/v1beta1/tagbinding_identity.go

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,71 +13,3 @@
1313
// limitations under the License.
1414

1515
package v1beta1
16-
17-
import (
18-
"context"
19-
"fmt"
20-
21-
"sigs.k8s.io/controller-runtime/pkg/client"
22-
)
23-
24-
// TagBindingIdentity defines the resource reference to TagsTagBinding, which "External" field
25-
// holds the GCP identifier for the KRM object.
26-
type TagBindingIdentity struct {
27-
parent string
28-
tagValue string
29-
}
30-
31-
func (i *TagBindingIdentity) String() string {
32-
return fmt.Sprintf("tagBindings/%s/%s", i.parent, i.tagValue)
33-
}
34-
35-
func (i *TagBindingIdentity) Parent() string {
36-
return i.parent
37-
}
38-
39-
func (i *TagBindingIdentity) TagValue() string {
40-
return i.tagValue
41-
}
42-
43-
// New builds a TagBindingIdentity from the Config Connector TagBinding object.
44-
func NewTagBindingIdentity(ctx context.Context, reader client.Reader, obj *TagsTagBinding) (*TagBindingIdentity, error) {
45-
parent, err := resolveParent(ctx, reader, obj)
46-
if err != nil {
47-
return nil, err
48-
}
49-
50-
tagValue, err := resolveTagValue(ctx, reader, obj)
51-
if err != nil {
52-
return nil, err
53-
}
54-
55-
return &TagBindingIdentity{
56-
parent: parent,
57-
tagValue: tagValue,
58-
}, nil
59-
}
60-
61-
func resolveParent(ctx context.Context, reader client.Reader, obj *TagsTagBinding) (string, error) {
62-
if obj.Spec.ParentRef.External != "" {
63-
return obj.Spec.ParentRef.External, nil
64-
}
65-
if obj.Spec.ParentRef.Name != "" {
66-
// TODO: This is not quite right, we need to resolve the project number.
67-
// For now, we will just use the name.
68-
return fmt.Sprintf("//cloudresourcemanager.googleapis.com/projects/%s", obj.Spec.ParentRef.Name), nil
69-
}
70-
return "", fmt.Errorf("parentRef is required")
71-
}
72-
73-
func resolveTagValue(ctx context.Context, reader client.Reader, obj *TagsTagBinding) (string, error) {
74-
if obj.Spec.TagValueRef.External != "" {
75-
return obj.Spec.TagValueRef.External, nil
76-
}
77-
if obj.Spec.TagValueRef.Name != "" {
78-
// TODO: This is not quite right, we need to resolve the tag value name.
79-
// For now, we will just use the name.
80-
return fmt.Sprintf("tagValues/%s", obj.Spec.TagValueRef.Name), nil
81-
}
82-
return "", fmt.Errorf("tagValueRef is required")
83-
}

apis/tags/v1beta1/tagbinding_reference.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,3 @@
1313
// limitations under the License.
1414

1515
package v1beta1
16-
17-
import (
18-
"context"
19-
"fmt"
20-
21-
refsv1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1"
22-
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s"
23-
apierrors "k8s.io/apimachinery/pkg/api/errors"
24-
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
25-
"k8s.io/apimachinery/pkg/types"
26-
"sigs.k8s.io/controller-runtime/pkg/client"
27-
)
28-
29-
var _ refsv1beta1.ExternalNormalizer = &TagsTagValueRef{}
30-
31-
// NormalizedExternal provision the "External" value for other resource that depends on TagsTagValue.
32-
// If the "External" is given in the other resource's spec.TagsTagValueRef, the given value will be used.
33-
// Otherwise, the "Name" and "Namespace" will be used to query the actual TagsTagValue object from the cluster.
34-
func (r *TagsTagValueRef) NormalizedExternal(ctx context.Context, reader client.Reader, otherNamespace string) (string, error) {
35-
if r.External != "" && r.Name != "" {
36-
return "", fmt.Errorf("cannot specify both name and external on %s reference", "TagsTagValue")
37-
}
38-
// From given External
39-
if r.External != "" {
40-
return r.External, nil
41-
}
42-
43-
// From the Config Connector object
44-
if r.Namespace == "" {
45-
r.Namespace = otherNamespace
46-
}
47-
key := types.NamespacedName{Name: r.Name, Namespace: r.Namespace}
48-
u := &unstructured.Unstructured{}
49-
u.SetGroupVersionKind(GroupVersion.WithKind("TagsTagValue"))
50-
if err := reader.Get(ctx, key, u); err != nil {
51-
if apierrors.IsNotFound(err) {
52-
return "", k8s.NewReferenceNotFoundError(u.GroupVersionKind(), key)
53-
}
54-
return "", fmt.Errorf("reading referenced %s %s: %w", "TagsTagValue", key, err)
55-
}
56-
// Get external from status.selfLink. This is the most trustworthy place.
57-
actualExternalRef, _, err := unstructured.NestedString(u.Object, "status", "selfLink")
58-
if err != nil {
59-
return "", fmt.Errorf("reading status.selfLink: %w", err)
60-
}
61-
if actualExternalRef == "" {
62-
return "", k8s.NewReferenceNotReadyError(u.GroupVersionKind(), key)
63-
}
64-
r.External = actualExternalRef
65-
return r.External, nil
66-
}

apis/tags/v1beta1/zz_generated.deepcopy.go

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)