Skip to content

Commit 22a9b31

Browse files
committed
chore: tweak schema for forwardingRule -> memorystore service attachemnt
Also we finally hit a circular dependency between compute and memorystore, so we need to move the instance identity and ref into its own package, that both compute and memorystore can use without creating a circular dependency.
1 parent 41ed66b commit 22a9b31

18 files changed

+238
-436
lines changed

apis/compute/v1beta1/forwardingrule_types.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package v1beta1
1616

1717
import (
18+
"github.com/GoogleCloudPlatform/k8s-config-connector/apis/memorystore/memorystorerefs"
1819
refs "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1"
1920
commonv1alpha1 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/common/v1alpha1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -85,9 +86,9 @@ type Target struct {
8586
// +optional
8687
GoogleAPIsBundle *string `json:"googleAPIsBundle,omitempty"`
8788

88-
// The service attachment for a Memorystore for Valkey instance.
89+
// Target a serviceAttachment for a Memorystore for Valkey instance.
8990
// +optional
90-
MemorystoreInstanceServiceAttachmentRef *refs.MemorystoreInstanceServiceAttachmentRef `json:"memorystoreInstanceServiceAttachmentRef,omitempty"`
91+
MemorystoreInstanceServiceAttachment *MemorystoreInstanceServiceAttachment `json:"memorystoreInstanceServiceAttachment,omitempty"`
9192

9293
// +optional
9394
ServiceAttachmentRef *refs.ComputeServiceAttachmentRef `json:"serviceAttachmentRef,omitempty"`
@@ -111,6 +112,22 @@ type Target struct {
111112
TargetVPNGatewayRef *refs.ComputeTargetVPNGatewayRef `json:"targetVPNGatewayRef,omitempty"`
112113
}
113114

115+
// MemorystoreInstanceServiceAttachment defines the resource reference to the GCP identifier
116+
// for the ServiceAttachment managed by the MemorystoreInstance pointed by the MemorystoreInstanceRef.
117+
// +k8s:deepcopy-gen=true
118+
type MemorystoreInstanceServiceAttachment struct {
119+
// A reference to a MemorystoreInstance resource.
120+
// +required
121+
MemorystoreInstanceRef *memorystorerefs.InstanceRef `json:"memorystoreInstanceRef,omitempty"`
122+
123+
// The connection type of the serviceAttachment.
124+
// A memorystore instance has multiple serviceAttachments, each with a different connection type.
125+
// Use connectionType to control which serviceAttachment to target.
126+
// The empty value matches a serviceAttachment with an empty connectionType.
127+
// +optional
128+
ConnectionType *string `json:"connectionType,omitempty"`
129+
}
130+
114131
// +kcc:spec:proto=google.cloud.compute.v1.ForwardingRule
115132
type ComputeForwardingRuleSpec struct {
116133
/* Immutable. This field can only be used:

apis/compute/v1beta1/zz_generated.deepcopy.go

Lines changed: 29 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package memorystorerefs
16+
17+
import (
18+
"fmt"
19+
"strings"
20+
)
21+
22+
// InstanceIdentity defines the resource reference to MemorystoreInstance, which "External" field
23+
// holds the GCP identifier for the KRM object.
24+
type InstanceIdentity struct {
25+
Parent_ *InstanceParent
26+
ID_ string
27+
}
28+
29+
func (i *InstanceIdentity) String() string {
30+
return i.Parent_.String() + "/instances/" + i.ID_
31+
}
32+
33+
func (i *InstanceIdentity) ID() string {
34+
return i.ID_
35+
}
36+
37+
func (i *InstanceIdentity) Parent() *InstanceParent {
38+
return i.Parent_
39+
}
40+
41+
type InstanceParent struct {
42+
ProjectID string
43+
Location string
44+
}
45+
46+
func (p *InstanceParent) String() string {
47+
return "projects/" + p.ProjectID + "/locations/" + p.Location
48+
}
49+
50+
func ParseInstanceExternal(external string) (parent *InstanceParent, resourceID string, err error) {
51+
tokens := strings.Split(external, "/")
52+
if len(tokens) != 6 || tokens[0] != "projects" || tokens[2] != "locations" || tokens[4] != "instances" {
53+
return nil, "", fmt.Errorf("format of MemorystoreInstance external=%q was not known (use projects/{{projectID}}/locations/{{location}}/instances/{{instanceID}})", external)
54+
}
55+
parent = &InstanceParent{
56+
ProjectID: tokens[1],
57+
Location: tokens[3],
58+
}
59+
resourceID = tokens[5]
60+
return parent, resourceID, nil
61+
}

apis/memorystore/v1beta1/instance_reference.go renamed to apis/memorystore/memorystorerefs/instance_reference.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package v1beta1
15+
package memorystorerefs
1616

1717
import (
1818
"context"
@@ -22,10 +22,17 @@ import (
2222
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s"
2323
apierrors "k8s.io/apimachinery/pkg/api/errors"
2424
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
25+
"k8s.io/apimachinery/pkg/runtime/schema"
2526
"k8s.io/apimachinery/pkg/types"
2627
"sigs.k8s.io/controller-runtime/pkg/client"
2728
)
2829

30+
var MemorystoreInstanceGVK = schema.GroupVersionKind{
31+
Group: "memorystore.cnrm.cloud.google.com",
32+
Version: "v1beta1",
33+
Kind: "MemorystoreInstance",
34+
}
35+
2936
var _ refsv1beta1.ExternalNormalizer = &InstanceRef{}
3037

3138
// InstanceRef defines the resource reference to MemorystoreInstance, which "External" field

apis/memorystore/v1alpha1/endpoint_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package v1alpha1
1616

1717
import (
1818
computev1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/compute/v1beta1"
19-
refsv1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1"
19+
"github.com/GoogleCloudPlatform/k8s-config-connector/apis/memorystore/memorystorerefs"
2020
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/k8s/v1alpha1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222
)
@@ -28,7 +28,7 @@ var MemorystoreInstanceEndpointGVK = GroupVersion.WithKind("MemorystoreInstanceE
2828
type MemorystoreInstanceEndpointSpec struct {
2929
// Required. The Memorystore instance reference of the endpoint.
3030
// +required
31-
InstanceRef *refsv1beta1.MemorystoreInstanceRef `json:"instanceRef"`
31+
InstanceRef *memorystorerefs.InstanceRef `json:"instanceRef"`
3232

3333
// Optional. The MemorystoreInstanceEndpoint name. If not given, the metadata.name will be used.
3434
// +optional

apis/memorystore/v1alpha1/zz_generated.deepcopy.go

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

apis/memorystore/v1beta1/instance_identity.go

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)