Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#3603 from gemmahou/cloudidenti…
Browse files Browse the repository at this point in the history
…tygroup-mappers

feat: Add CloudIdentityGroup mappers
  • Loading branch information
google-oss-prow[bot] authored Feb 11, 2025
2 parents 5af3b35 + 92d0cc4 commit 2f67a70
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 35 deletions.
21 changes: 7 additions & 14 deletions apis/cloudidentity/v1beta1/group_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package v1beta1

import (
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/apis/k8s/v1alpha1"
commonv1alpha1 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/common/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -43,7 +43,7 @@ type CloudIdentityGroupSpec struct {
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="GroupKey field is immutable"
// Immutable. EntityKey of the Group.
// +required
GroupKey EntityKey `json:"groupKey"`
GroupKey *EntityKey `json:"groupKey"`

// Immutable. The initial configuration options for creating a Group. See the [API reference](https://cloud.google.com/identity/docs/reference/rest/v1beta1/groups/create#initialgroupconfig) for possible values. Default value: "EMPTY" Possible values: ["INITIAL_GROUP_CONFIG_UNSPECIFIED", "WITH_INITIAL_OWNER", "EMPTY"].
InitialGroupConfig *string `json:"initialGroupConfig,omitempty"`
Expand All @@ -62,10 +62,9 @@ type CloudIdentityGroupSpec struct {
}

// CloudIdentityGroupStatus defines the config connector machine state of CloudIdentityGroup
// +kcc:proto=mockgcp.cloud.cloudidentity.groups.v1beta1.Group
type CloudIdentityGroupStatus struct {
/* Conditions represent the latest available observations of the
object's current state. */
Conditions []v1alpha1.Condition `json:"conditions,omitempty"`
commonv1alpha1.CommonStatus `json:",inline"`

// The time when the `Group` was created.
// +kcc:proto:field=mockgcp.cloud.cloudidentity.groups.v1beta1.Group.create_time
Expand All @@ -75,18 +74,12 @@ type CloudIdentityGroupStatus struct {
// +kcc:proto:field=mockgcp.cloud.cloudidentity.groups.v1beta1.Group.name
Name *string `json:"name,omitempty"`

// A unique specifier for the CloudIdentityGroup resource in GCP.
ExternalRef *string `json:"externalRef,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"`

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

// The time when the `Group` was last updated.
// +kcc:proto:field=mockgcp.cloud.cloudidentity.groups.v1beta1.Group.update_time
UpdateTime *string `json:"updateTime,omitempty"`

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

// CloudIdentityGroupObservedState is the state of the CloudIdentityGroup resource as most recently observed in GCP.
Expand Down
27 changes: 8 additions & 19 deletions apis/cloudidentity/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 @@ -167,7 +167,7 @@ spec:
description: The time when the `Group` was created.
type: string
externalRef:
description: A unique specifier for the CloudIdentityGroup resource
description: A unique Config Connector specifier for the resource
in GCP.
type: string
name:
Expand Down
47 changes: 47 additions & 0 deletions pkg/controller/direct/cloudidentity/group_fuzzer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2025 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 cloudidentity

import (
pb "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/generated/mockgcp/cloud/cloudidentity/groups/v1beta1"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/fuzztesting"
)

func init() {
fuzztesting.RegisterKRMFuzzer(cloudIdentityGroupFuzzer())
}

func cloudIdentityGroupFuzzer() fuzztesting.KRMFuzzer {
f := fuzztesting.NewKRMTypedFuzzer(&pb.Group{},
CloudIdentityGroupSpec_FromProto, CloudIdentityGroupSpec_ToProto,
CloudIdentityGroupStatus_FromProto, CloudIdentityGroupStatus_ToProto,
)

f.UnimplementedFields.Insert(".posix_groups")
f.UnimplementedFields.Insert(".dynamic_group_metadata")

f.SpecFields.Insert(".display_name")
f.SpecFields.Insert(".description")
f.SpecFields.Insert(".group_key")
f.SpecFields.Insert(".labels")
f.SpecFields.Insert(".parent")

f.StatusFields.Insert(".name")
f.StatusFields.Insert(".create_time")
f.StatusFields.Insert(".update_time")
f.StatusFields.Insert(".additional_group_keys")

return f
}
106 changes: 106 additions & 0 deletions pkg/controller/direct/cloudidentity/group_mapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright 2025 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 cloudidentity

import (
krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/cloudidentity/v1beta1"
_ "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1"
pb "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/generated/mockgcp/cloud/cloudidentity/groups/v1beta1"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct"
)

func CloudIdentityGroupObservedState_FromProto(mapCtx *direct.MapContext, in *pb.Group) *krm.CloudIdentityGroupObservedState {
if in == nil {
return nil
}
out := &krm.CloudIdentityGroupObservedState{}
out.AdditionalGroupKeys = direct.Slice_FromProto(mapCtx, in.AdditionalGroupKeys, EntityKey_FromProto)
return out
}
func CloudIdentityGroupObservedState_ToProto(mapCtx *direct.MapContext, in *krm.CloudIdentityGroupObservedState) *pb.Group {
if in == nil {
return nil
}
out := &pb.Group{}
out.AdditionalGroupKeys = direct.Slice_ToProto(mapCtx, in.AdditionalGroupKeys, EntityKey_ToProto)
return out
}
func CloudIdentityGroupSpec_FromProto(mapCtx *direct.MapContext, in *pb.Group) *krm.CloudIdentityGroupSpec {
if in == nil {
return nil
}
out := &krm.CloudIdentityGroupSpec{}
out.Description = in.Description
out.DisplayName = in.DisplayName
out.GroupKey = EntityKey_FromProto(mapCtx, in.GetGroupKey())
out.Labels = in.Labels
out.Parent = in.Parent
return out
}
func CloudIdentityGroupSpec_ToProto(mapCtx *direct.MapContext, in *krm.CloudIdentityGroupSpec) *pb.Group {
if in == nil {
return nil
}
out := &pb.Group{}
out.Description = in.Description
out.DisplayName = in.DisplayName
out.GroupKey = EntityKey_ToProto(mapCtx, in.GroupKey)
out.Labels = in.Labels
out.Parent = in.Parent
return out
}
func CloudIdentityGroupStatus_FromProto(mapCtx *direct.MapContext, in *pb.Group) *krm.CloudIdentityGroupStatus {
if in == nil {
return nil
}
out := &krm.CloudIdentityGroupStatus{}
out.CreateTime = direct.StringTimestamp_FromProto(mapCtx, in.GetCreateTime())
out.Name = in.Name
out.UpdateTime = direct.StringTimestamp_FromProto(mapCtx, in.GetUpdateTime())
out.ObservedState = CloudIdentityGroupObservedState_FromProto(mapCtx, in)
return out
}
func CloudIdentityGroupStatus_ToProto(mapCtx *direct.MapContext, in *krm.CloudIdentityGroupStatus) *pb.Group {
if in == nil {
return nil
}
out := &pb.Group{}
out.CreateTime = direct.StringTimestamp_ToProto(mapCtx, in.CreateTime)
out.Name = in.Name
out.UpdateTime = direct.StringTimestamp_ToProto(mapCtx, in.UpdateTime)
observedState := CloudIdentityGroupObservedState_ToProto(mapCtx, in.ObservedState)
if observedState != nil {
out.AdditionalGroupKeys = observedState.AdditionalGroupKeys
}
return out
}
func EntityKey_FromProto(mapCtx *direct.MapContext, in *pb.EntityKey) *krm.EntityKey {
if in == nil {
return nil
}
out := &krm.EntityKey{}
out.ID = direct.ValueOf(in.Id)
out.Namespace = in.Namespace
return out
}
func EntityKey_ToProto(mapCtx *direct.MapContext, in *krm.EntityKey) *pb.EntityKey {
if in == nil {
return nil
}
out := &pb.EntityKey{}
out.Id = direct.LazyPtr(in.ID)
out.Namespace = in.Namespace
return out
}
1 change: 1 addition & 0 deletions pkg/controller/direct/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
_ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/bigquerydatatransfer"
_ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/certificatemanager"
_ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/cloudbuild"
_ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/cloudidentity"
_ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/compute/firewallpolicyrule"
_ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/compute/forwardingrule"
_ "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/compute/targettcpproxy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ updateTime: string
<td><code>externalRef</code></td>
<td>
<p><code class="apitype">string</code></p>
<p>{% verbatim %}A unique specifier for the CloudIdentityGroup resource in GCP.{% endverbatim %}</p>
<p>{% verbatim %}A unique Config Connector specifier for the resource in GCP.{% endverbatim %}</p>
</td>
</tr>
<tr>
Expand Down

0 comments on commit 2f67a70

Please sign in to comment.