Skip to content

Commit

Permalink
feat: Implement sqlinstance direct controller
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvigil committed Aug 8, 2024
1 parent 8c49d75 commit 91aac51
Show file tree
Hide file tree
Showing 44 changed files with 3,727 additions and 922 deletions.
5 changes: 3 additions & 2 deletions apis/refs/v1beta1/computerefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"strings"

"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -27,7 +28,7 @@ import (
)

type ComputeNetworkRef struct {
/* The compute network selflink of form "projects/<project>/global/networks/<network>", when not managed by KCC. */
/* The compute network selflink of form "projects/<project>/global/networks/<network>", when not managed by Config Connector. */
External string `json:"external,omitempty"`
/* The `name` field of a `ComputeNetwork` resource. */
Name string `json:"name,omitempty"`
Expand Down Expand Up @@ -83,7 +84,7 @@ func ResolveComputeNetwork(ctx context.Context, reader client.Reader, src client
})
if err := reader.Get(ctx, key, computenetwork); err != nil {
if apierrors.IsNotFound(err) {
return nil, fmt.Errorf("referenced ComputeNetwork %v not found", key)
return nil, k8s.NewReferenceNotFoundError(computenetwork.GroupVersionKind(), key)
}
return nil, fmt.Errorf("error reading referenced ComputeNetwork %v: %w", key, err)
}
Expand Down
24 changes: 24 additions & 0 deletions apis/refs/v1beta1/sqlinstanceref.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1beta1

type SQLInstanceRef struct {
/* The SQLInstance selfLink, when not managed by Config Connector. */
External string `json:"external,omitempty"`
/* The `name` field of a `SQLInstance` resource. */
Name string `json:"name,omitempty"`
/* The `namespace` field of a `SQLInstance` resource. */
Namespace string `json:"namespace,omitempty"`
}
24 changes: 24 additions & 0 deletions apis/refs/v1beta1/storagebucketref.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1beta1

type StorageBucketRef struct {
/* The StorageBucket selfLink, when not managed by Config Connector. */
External string `json:"external,omitempty"`
/* The `name` field of a `StorageBucket` resource. */
Name string `json:"name,omitempty"`
/* The `namespace` field of a `StorageBucket` resource. */
Namespace string `json:"namespace,omitempty"`
}
15 changes: 10 additions & 5 deletions apis/sql/v1beta1/sqlinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"

refsv1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/apis/k8s/v1alpha1"
)

Expand Down Expand Up @@ -161,7 +162,7 @@ type InstanceIpConfiguration struct {
Ipv4Enabled *bool `json:"ipv4Enabled,omitempty"`

// +optional
PrivateNetworkRef *v1alpha1.ResourceRef `json:"privateNetworkRef,omitempty"`
PrivateNetworkRef *refsv1beta1.ComputeNetworkRef `json:"privateNetworkRef,omitempty"`

/* PSC settings for a Cloud SQL instance. */
// +optional
Expand Down Expand Up @@ -203,6 +204,8 @@ type InstanceMaintenanceWindow struct {
UpdateTrack *string `json:"updateTrack,omitempty"`
}

// +kubebuilder:validation:XValidation:rule="has(self.value) ? !has(self.valueFrom) : true",message="valueFrom is forbidden when value is specified"
// +kubebuilder:validation:XValidation:rule="has(self.valueFrom) ? !has(self.value): true",message="value is forbidden when valueFrom is specified"
type InstancePassword struct {
/* Value of the field. Cannot be used if 'valueFrom' is specified. */
// +optional
Expand Down Expand Up @@ -294,6 +297,8 @@ type InstanceReplicaConfiguration struct {
VerifyServerCertificate *bool `json:"verifyServerCertificate,omitempty"`
}

// +kubebuilder:validation:XValidation:rule="has(self.value) ? !has(self.valueFrom) : true",message="valueFrom is forbidden when value is specified"
// +kubebuilder:validation:XValidation:rule="has(self.valueFrom) ? !has(self.value): true",message="value is forbidden when valueFrom is specified"
type InstanceRootPassword struct {
/* Value of the field. Cannot be used if 'valueFrom' is specified. */
// +optional
Expand Down Expand Up @@ -419,7 +424,7 @@ type InstanceSettings struct {
type InstanceSqlServerAuditConfig struct {
/* The name of the destination bucket (e.g., gs://mybucket). */
// +optional
BucketRef *v1alpha1.ResourceRef `json:"bucketRef,omitempty"`
BucketRef *refsv1beta1.StorageBucketRef `json:"bucketRef,omitempty"`

/* How long to keep generated audit files. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".. */
// +optional
Expand All @@ -442,7 +447,7 @@ type SQLInstanceSpec struct {
DatabaseVersion *string `json:"databaseVersion,omitempty"`

// +optional
EncryptionKMSCryptoKeyRef *v1alpha1.ResourceRef `json:"encryptionKMSCryptoKeyRef,omitempty"`
EncryptionKMSCryptoKeyRef *refsv1beta1.KMSCryptoKeyRef `json:"encryptionKMSCryptoKeyRef,omitempty"`

/* The type of the instance. The valid values are:- 'SQL_INSTANCE_TYPE_UNSPECIFIED', 'CLOUD_SQL_INSTANCE', 'ON_PREMISES_INSTANCE' and 'READ_REPLICA_INSTANCE'. */
// +optional
Expand All @@ -453,7 +458,7 @@ type SQLInstanceSpec struct {
MaintenanceVersion *string `json:"maintenanceVersion,omitempty"`

// +optional
MasterInstanceRef *v1alpha1.ResourceRef `json:"masterInstanceRef,omitempty"`
MasterInstanceRef *refsv1beta1.SQLInstanceRef `json:"masterInstanceRef,omitempty"`

/* Immutable. The region the instance will sit in. Note, Cloud SQL is not available in all regions. A valid region must be provided to use this resource. If a region is not provided in the resource definition, the provider region will be used instead, but this will be an apply-time error for instances if the provider region is not supported with Cloud SQL. If you choose not to provide the region argument for this resource, make sure you understand this. */
// +optional
Expand Down Expand Up @@ -576,7 +581,7 @@ type SQLInstance struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec SQLInstanceSpec `json:"spec,omitempty"`
Spec SQLInstanceSpec `json:"spec"`
Status SQLInstanceStatus `json:"status,omitempty"`
}

Expand Down
9 changes: 5 additions & 4 deletions apis/sql/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ spec:
properties:
external:
description: The compute network selflink of form "projects/<project>/global/networks/<network>",
when not managed by KCC.
when not managed by Config Connector.
type: string
name:
description: The `name` field of a `ComputeNetwork` resource.
Expand Down Expand Up @@ -276,7 +276,7 @@ spec:
properties:
external:
description: The compute network selflink of form "projects/<project>/global/networks/<network>",
when not managed by KCC.
when not managed by Config Connector.
type: string
name:
description: The `name` field of a `ComputeNetwork` resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ spec:
properties:
external:
description: The compute network selflink of form "projects/<project>/global/networks/<network>",
when not managed by KCC.
when not managed by Config Connector.
type: string
name:
description: The `name` field of a `ComputeNetwork` resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ spec:
properties:
external:
description: The compute network selflink of form "projects/<project>/global/networks/<network>",
when not managed by KCC.
when not managed by Config Connector.
type: string
name:
description: The `name` field of a `ComputeNetwork` resource.
Expand Down Expand Up @@ -264,7 +264,7 @@ spec:
external:
description: The compute network selflink of form
"projects/<project>/global/networks/<network>",
when not managed by KCC.
when not managed by Config Connector.
type: string
name:
description: The `name` field of a `ComputeNetwork`
Expand Down
Loading

0 comments on commit 91aac51

Please sign in to comment.