Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promoting autokey config from alpha to beta #3012

Closed
wants to merge 76 commits into from
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
e2c3a30
intial commit to move autokeyconfig to beta
nb-goog Oct 26, 2024
0093e0d
part2 alpha to beta autokeyconfig
nb-goog Oct 28, 2024
f8dd4b5
Part3 updated
nb-goog Oct 28, 2024
a24f87b
part 4
nb-goog Oct 28, 2024
63e1362
part 5
nb-goog Oct 28, 2024
37369c3
Part 6
nb-goog Oct 28, 2024
d8cff19
Part 7
nb-goog Oct 28, 2024
6113053
Merge branch 'master' into configToBeta
nb-goog Oct 28, 2024
2fc2e06
part 8
nb-goog Oct 28, 2024
0c50f89
Review commetns
nb-goog Oct 28, 2024
31d403e
correcting unit test build error
nb-goog Oct 29, 2024
27c769a
Make ready pr
nb-goog Oct 29, 2024
db81600
init for dummy branch
nb-goog Oct 29, 2024
2aa66a3
Revert "init for dummy branch"
nb-goog Oct 29, 2024
c42851d
Updating gvk_generated.go
nb-goog Oct 29, 2024
0d15d09
fix: Fix SQLInstance authorizednetworks periodic
jasonvigil Oct 25, 2024
5dd10c0
Add script to update images in expander-helm
cheftako Oct 28, 2024
71624a2
chore: change type-generators to give shorter api _types.go file name
yuwenma Oct 28, 2024
937e802
chore: drop redundant service name from api type file
yuwenma Oct 28, 2024
8bf8189
removing accidental file
nb-goog Oct 29, 2024
5c7af1a
Merge branch 'GoogleCloudPlatform:master' into configToBeta
nb-goog Oct 29, 2024
479ae85
Merge branch 'GoogleCloudPlatform:master' into configToBeta
nb-goog Oct 29, 2024
feca97c
Make readypr
nb-goog Oct 29, 2024
d68a81f
Merge branch 'GoogleCloudPlatform:master' into configToBeta
nb-goog Oct 30, 2024
3aa92e3
Merge branch 'master' into configToBeta
nb-goog Nov 1, 2024
bdb8597
Merge branch 'GoogleCloudPlatform:master' into master
nb-goog Nov 1, 2024
c15db8f
Merge branch 'master' into configToBeta
nb-goog Nov 1, 2024
8276a97
Merge branch 'master' into configToBeta
nb-goog Nov 2, 2024
978d94c
Merge branch 'GoogleCloudPlatform:master' into master
nb-goog Nov 4, 2024
4fa2423
initial key handle commit
nb-goog Oct 25, 2024
227dda1
delete accidentally committed files
nb-goog Oct 25, 2024
ce5d201
Make ready-pr
nb-goog Oct 25, 2024
61825b4
Removing todos
nb-goog Oct 25, 2024
ce23406
updating tests
nb-goog Oct 25, 2024
ad7d7e6
Updated as per bigquery connection controller
nb-goog Oct 29, 2024
0a04772
adding comments
nb-goog Oct 29, 2024
9cad704
addressing review comments
nb-goog Oct 29, 2024
3546d3b
real gcp logs
nb-goog Nov 1, 2024
f414439
minor nits
yuwenma Nov 2, 2024
0ca4ecc
fix dynamic test cloudspannerconnectionbasic
yuwenma Oct 30, 2024
4e33770
chore: handle name in bqcc update
yuwenma Oct 31, 2024
1c12eb4
use update field mask to deterine which field to update
yuwenma Nov 1, 2024
1dd1df0
real gcp record
yuwenma Nov 1, 2024
4b418f4
mock gcp
yuwenma Nov 1, 2024
42cb3c7
update field mask is better than I thought
yuwenma Nov 1, 2024
a2d559c
fix: cbwp GCP server request/response project in different format
yuwenma Oct 29, 2024
e888c70
compare real gcp
yuwenma Oct 30, 2024
561c6e9
chore: rename projectIDAndNumber
yuwenma Oct 30, 2024
06df27c
chore: Mock CBWP use handler function to update object by field mask
yuwenma Nov 1, 2024
5af4008
build project ID and Number switcher around NetworkRef
yuwenma Nov 2, 2024
e4fbce5
Promote PrivilegedAccessManagerEntitlement to v1beta1
maqiuyujoyce Oct 25, 2024
ef5d825
Rerun 'make ready-pr'"
maqiuyujoyce Nov 1, 2024
91f9f92
Run 'make ensure'
maqiuyujoyce Nov 1, 2024
a5a6552
Enable placeholder 'GROUP_EMAIL' in mock sample test
maqiuyujoyce Nov 2, 2024
b106266
tests: normalize addresses for RedisInstance
justinsb Oct 31, 2024
4da8584
mockgcp: more fidelity for container APIs
justinsb Oct 31, 2024
66013ff
tests: update golden output
justinsb Nov 1, 2024
cba7866
chore: fix turbo-e2e script to work on mac
justinsb Nov 1, 2024
1ae3223
DiscoveryEngineDataStore: mockgcp support
justinsb Oct 24, 2024
0348678
mockgcp: generate code for discoveryengine
justinsb Oct 23, 2024
422d0ae
DiscoveryEngineDataStore: protos for mockgcp
justinsb Oct 24, 2024
30b844d
DiscoveryEngineDataStore: golden output for mockgcp
justinsb Oct 24, 2024
9ed3aa3
DiscoveryEngineDataStore: fix golden output
justinsb Nov 1, 2024
acf3643
tests: clearer log when waiting for webhook
justinsb Nov 2, 2024
d3e31a1
tests: rename tests with same name
justinsb Oct 31, 2024
e168ca4
docs: Generate better titles for samples
justinsb Oct 31, 2024
8b9eada
Merge branch 'master' into configToBeta
nb-goog Nov 4, 2024
e527685
removing apis/kms/v1alpha1
nb-goog Nov 4, 2024
658ee6d
Revert "removing apis/kms/v1alpha1"
nb-goog Nov 4, 2024
9cf52ce
removing autokeyconfig from v1alpha1
nb-goog Nov 4, 2024
c53806f
Merge branch 'master' into configToBeta
nb-goog Nov 7, 2024
e9a1351
Merge branch 'GoogleCloudPlatform:master' into configToBeta
nb-goog Nov 8, 2024
ef23053
Merge branch 'GoogleCloudPlatform:master' into configToBeta
nb-goog Nov 11, 2024
932c60d
Merge branch 'GoogleCloudPlatform:master' into configToBeta
nb-goog Nov 12, 2024
f0747be
intial commit to move autokeyconfig to beta
nb-goog Oct 26, 2024
2f8d4ce
Merge branch 'GoogleCloudPlatform:master' into configToBeta
nb-goog Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions apis/kms/v1beta1/autokeyconfig_reference.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// 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

import (
"context"
"fmt"
"strings"

refsv1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1"
"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/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var _ refsv1beta1.ExternalNormalizer = &KMSAutokeyConfigRef{}

// KMSAutokeyConfigRef defines the resource reference to KMSAutokeyConfig, which "External" field
// holds the GCP identifier for the KRM object.
type KMSAutokeyConfigRef struct {
// A reference to an externally managed KMSAutokeyConfig resource.
// Should be in the format "folders/<folderID>/autokeyConfig".
External string `json:"external,omitempty"`

// The name of a KMSAutokeyConfig resource.
Name string `json:"name,omitempty"`

// The namespace of a KMSAutokeyConfig resource.
Namespace string `json:"namespace,omitempty"`

parent *KMSAutokeyConfigParent
}

// NormalizedExternal provision the "External" value for other resource that depends on KMSAutokeyConfig.
// If the "External" is given in the other resource's spec.KMSAutokeyConfigRef, the given value will be used.
// Otherwise, the "Name" and "Namespace" will be used to query the actual KMSAutokeyConfig object from the cluster.
func (r *KMSAutokeyConfigRef) NormalizedExternal(ctx context.Context, reader client.Reader, otherNamespace string) (string, error) {
if r.External != "" && r.Name != "" {
return "", fmt.Errorf("cannot specify both name and external on %s reference", KMSAutokeyConfigGVK.Kind)
}
// From given External
if r.External != "" {
if _, err := ParseKMSAutokeyConfigExternal(r.External); err != nil {
return "", err
}
return r.External, nil
}

// From the Config Connector object
if r.Namespace == "" {
r.Namespace = otherNamespace
}
key := types.NamespacedName{Name: r.Name, Namespace: r.Namespace}
u := &unstructured.Unstructured{}
u.SetGroupVersionKind(KMSAutokeyConfigGVK)
if err := reader.Get(ctx, key, u); err != nil {
if apierrors.IsNotFound(err) {
return "", k8s.NewReferenceNotFoundError(u.GroupVersionKind(), key)
}
return "", fmt.Errorf("reading referenced %s %s: %w", KMSAutokeyConfigGVK, key, err)
}
// Get external from status.externalRef. This is the most trustworthy place.
actualExternalRef, _, err := unstructured.NestedString(u.Object, "status", "externalRef")
if err != nil {
return "", fmt.Errorf("reading status.externalRef: %w", err)
}
if actualExternalRef == "" {
return "", k8s.NewReferenceNotReadyError(u.GroupVersionKind(), key)
}
r.External = actualExternalRef
return r.External, nil
}

// New builds a KMSAutokeyConfigRef from the Config Connector KMSAutokeyConfig object.
func NewKMSAutokeyConfigRef(ctx context.Context, reader client.Reader, obj *KMSAutokeyConfig) (*KMSAutokeyConfigRef, error) {
id := &KMSAutokeyConfigRef{}

// Get Parent
folderRef, err := refsv1beta1.ResolveFolder(ctx, reader, obj, obj.Spec.FolderRef)
if err != nil {
return nil, err
}
folderID := folderRef.FolderID
if folderID == "" {
return nil, fmt.Errorf("cannot resolve project")
}
id.parent = &KMSAutokeyConfigParent{FolderID: folderID}

// Use approved External
externalRef := valueOf(obj.Status.ExternalRef)
if externalRef == "" {
id.External = AsKMSAutokeyConfigExternal(id.parent)
return id, nil
}

// Validate desired with actual
actualParent, err := ParseKMSAutokeyConfigExternal(externalRef)
if err != nil {
return nil, err
}
if actualParent.FolderID != folderID {
return nil, fmt.Errorf("spec.folderRef changed, expect %s, got %s", actualParent.FolderID, folderID)
}
id.External = externalRef
id.parent = &KMSAutokeyConfigParent{FolderID: folderID}
return id, nil
}

func (r *KMSAutokeyConfigRef) Parent() (*KMSAutokeyConfigParent, error) {
if r.parent != nil {
return r.parent, nil
}
if r.External != "" {
parent, err := ParseKMSAutokeyConfigExternal(r.External)
if err != nil {
return nil, err
}
return parent, nil
}
return nil, fmt.Errorf("KMSAutokeyConfigRef not initialized from `NewKMSAutokeyConfigRef` or `NormalizedExternal`")
}

type KMSAutokeyConfigParent struct {
FolderID string
}

func (p *KMSAutokeyConfigParent) String() string {
return "folders/" + p.FolderID
}

func AsKMSAutokeyConfigExternal(parent *KMSAutokeyConfigParent) (external string) {
return parent.String() + "/autokeyConfig"
}

func ParseKMSAutokeyConfigExternal(external string) (parent *KMSAutokeyConfigParent, err error) {
external = strings.TrimPrefix(external, "/")
tokens := strings.Split(external, "/")
if len(tokens) != 3 || tokens[0] != "folders" || tokens[2] != "autokeyConfig" {
return nil, fmt.Errorf("format of KMSAutokeyConfig external=%q was not known (use folders/<folderID>/autokeyConfig)", external)
}
parent = &KMSAutokeyConfigParent{
FolderID: tokens[1],
}
return parent, nil
}

func valueOf[T any](t *T) T {
var zeroVal T
if t == nil {
return zeroVal
}
return *t
}
16 changes: 0 additions & 16 deletions apis/kms/v1beta1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,3 @@
// +kcc:proto=google.cloud.kms.v1

package v1beta1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}

// AddToScheme is a global function that registers this API group & version to a scheme
AddToScheme = SchemeBuilder.AddToScheme

// SchemeGroupVersion is the group version used to register these objects.
SchemeGroupVersion = schema.GroupVersion{Group: "kms.cnrm.cloud.google.com", Version: "v1beta1"}
)
33 changes: 33 additions & 0 deletions apis/kms/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.

// +kubebuilder:object:generate=true
// +groupName=kms.cnrm.cloud.google.com
package v1beta1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}

// AddToScheme is a global function that registers this API group & version to a scheme
AddToScheme = SchemeBuilder.AddToScheme

// SchemeGroupVersion is the group version used to register these objects.
SchemeGroupVersion = schema.GroupVersion{Group: "kms.cnrm.cloud.google.com", Version: "v1beta1"}
)
97 changes: 97 additions & 0 deletions apis/kms/v1beta1/kmsautokeyconfig_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// 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

import (
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/k8s/v1alpha1"

refs "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var KMSAutokeyConfigGVK = SchemeGroupVersion.WithKind("KMSAutokeyConfig")

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// KMSAutokeyConfigSpec defines the desired state of KMSAutokeyConfig
// +kcc:proto=google.cloud.kms.v1.AutokeyConfig
type KMSAutokeyConfigSpec struct {

// NOTE: ResourceID field is not required for AutokeyConfig as its ID has the format folders/<folderID>/autokeyConfig i.e., it doesnt have any unique ID of its own and relies on folderID for uniqueness.

// Immutable. The folder that this resource belongs to.
// +required
FolderRef *refs.FolderRef `json:"folderRef"`

// +optional
KeyProjectRef *refs.ProjectRef `json:"keyProject,omitempty"`
}

// KMSAutokeyConfigStatus defines the config connector machine state of KMSAutokeyConfig
type KMSAutokeyConfigStatus struct {
/* Conditions represent the latest available observations of the
object's current state. */
Conditions []v1alpha1.Condition `json:"conditions,omitempty"`

// ObservedGeneration is the generation of the resource that was most recently observed by the Config Connector controller. If this is equal to metadata.generation, then that means that the current reported status reflects the most recent desired state of the resource.
ObservedGeneration *int64 `json:"observedGeneration,omitempty"`

// A unique specifier for the KMSAutokeyConfig resource in GCP.
ExternalRef *string `json:"externalRef,omitempty"`

// ObservedState is the state of the resource as most recently observed in GCP.
ObservedState *KMSAutokeyConfigObservedState `json:"observedState,omitempty"`
}

// KMSAutokeyConfigSpec defines the desired state of KMSAutokeyConfig
// +kcc:proto=google.cloud.kms.v1.AutokeyConfig
type KMSAutokeyConfigObservedState struct {
// Output only. Current state of this AutokeyConfig.
// +optional
State *string `json:"state,omitempty"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:categories=gcp,shortName=gcpkmsautokeyconfig;gcpkmsautokeyconfigs
// +kubebuilder:subresource:status
// +kubebuilder:metadata:labels="cnrm.cloud.google.com/managed-by-kcc=true";"cnrm.cloud.google.com/system=true";"cnrm.cloud.google.com/stability-level=beta"
// +kubebuilder:printcolumn:name="Age",JSONPath=".metadata.creationTimestamp",type="date"
// +kubebuilder:printcolumn:name="Ready",JSONPath=".status.conditions[?(@.type=='Ready')].status",type="string",description="When 'True', the most recent reconcile of the resource succeeded"
// +kubebuilder:printcolumn:name="Status",JSONPath=".status.conditions[?(@.type=='Ready')].reason",type="string",description="The reason for the value in 'Ready'"
// +kubebuilder:printcolumn:name="Status Age",JSONPath=".status.conditions[?(@.type=='Ready')].lastTransitionTime",type="date",description="The last transition time for the value in 'Status'"
// KMSAutokeyConfig is the Schema for the KMSAutokeyConfig API
// +k8s:openapi-gen=true
// +kubebuilder:storageversion
type KMSAutokeyConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec KMSAutokeyConfigSpec `json:"spec,omitempty"`
Status KMSAutokeyConfigStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// KMSAutokeyConfigList contains a list of KMSAutokeyConfig
type KMSAutokeyConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []KMSAutokeyConfig `json:"items"`
}

func init() {
SchemeBuilder.Register(&KMSAutokeyConfig{}, &KMSAutokeyConfigList{})
}
7 changes: 6 additions & 1 deletion apis/kms/v1beta1/types.generated.go

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

Loading
Loading