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

fix: Make WorkstationCluster network/subnetwork required #2820

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions apis/workstations/v1alpha1/workstationcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ type WorkstationClusterSpec struct {

// Immutable. Reference to the Compute Engine network in which instances associated
// with this workstation cluster will be created.
NetworkRef *refs.ComputeNetworkRef `json:"networkRef,omitempty"`
// +required
NetworkRef refs.ComputeNetworkRef `json:"networkRef"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I suggest using the // +required option to make this explicit

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!


// Immutable. Reference to the Compute Engine subnetwork in which instances
// associated with this workstation cluster will be created. Must be part of
// the subnetwork specified for this workstation cluster.
SubnetworkRef *refs.ComputeSubnetworkRef `json:"subnetworkRef,omitempty"`
// +required
SubnetworkRef refs.ComputeSubnetworkRef `json:"subnetworkRef"`

// Optional. Configuration for private workstation cluster.
PrivateClusterConfig *WorkstationCluster_PrivateClusterConfig `json:"privateClusterConfig,omitempty"`
Expand Down
12 changes: 2 additions & 10 deletions apis/workstations/v1alpha1/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 @@ -240,7 +240,9 @@ spec:
type: string
type: object
required:
- networkRef
- projectRef
- subnetworkRef
type: object
status:
description: WorkstationClusterStatus defines the config connector machine
Expand Down

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

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

50 changes: 11 additions & 39 deletions pkg/controller/direct/workstations/workstationcluster_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func WorkstationClusterSpec_ToProto(mapCtx *direct.MapContext, in *krm.Workstati
DisplayName: direct.ValueOf(in.DisplayName),
Annotations: WorkstationClusterAnnotations_ToProto(mapCtx, in.Annotations),
Labels: WorkstationClusterLabels_ToProto(mapCtx, in.Labels),
Network: WorkstationClusterNetworkRef_ToProto(mapCtx, in.NetworkRef),
Subnetwork: WorkstationClusterSubnetworkRef_ToProto(mapCtx, in.SubnetworkRef),
Network: in.NetworkRef.External,
Subnetwork: in.SubnetworkRef.External,
PrivateClusterConfig: WorkstationCluster_PrivateClusterConfig_ToProto(mapCtx, in.PrivateClusterConfig),
}
return out
Expand Down Expand Up @@ -60,20 +60,6 @@ func WorkstationClusterLabels_ToProto(mapCtx *direct.MapContext, in []krm.Workst
return out
}

func WorkstationClusterNetworkRef_ToProto(mapCtx *direct.MapContext, in *refs.ComputeNetworkRef) string {
if in == nil {
return ""
}
return in.External
}

func WorkstationClusterSubnetworkRef_ToProto(mapCtx *direct.MapContext, in *refs.ComputeSubnetworkRef) string {
if in == nil {
return ""
}
return in.External
}

func WorkstationCluster_PrivateClusterConfig_ToProto(mapCtx *direct.MapContext, in *krm.WorkstationCluster_PrivateClusterConfig) *pb.WorkstationCluster_PrivateClusterConfig {
if in == nil {
return nil
Expand Down Expand Up @@ -101,11 +87,15 @@ func WorkstationClusterSpec_FromProto(mapCtx *direct.MapContext, in *pb.Workstat
return nil
}
out := &krm.WorkstationClusterSpec{
DisplayName: direct.LazyPtr(in.GetDisplayName()),
Annotations: WorkstationClusterAnnotations_FromProto(mapCtx, in.GetAnnotations()),
Labels: WorkstationClusterLabels_FromProto(mapCtx, in.GetLabels()),
NetworkRef: WorkstationClusterNetworkRef_FromProto(mapCtx, in.GetNetwork()),
SubnetworkRef: WorkstationClusterSubnetworkRef_FromProto(mapCtx, in.GetSubnetwork()),
DisplayName: direct.LazyPtr(in.GetDisplayName()),
Annotations: WorkstationClusterAnnotations_FromProto(mapCtx, in.GetAnnotations()),
Labels: WorkstationClusterLabels_FromProto(mapCtx, in.GetLabels()),
NetworkRef: refs.ComputeNetworkRef{
External: in.GetNetwork(),
},
SubnetworkRef: refs.ComputeSubnetworkRef{
External: in.GetSubnetwork(),
},
PrivateClusterConfig: WorkstationCluster_PrivateClusterConfig_FromProto(mapCtx, in.GetPrivateClusterConfig()),
}
return out
Expand Down Expand Up @@ -139,24 +129,6 @@ func WorkstationClusterLabels_FromProto(mapCtx *direct.MapContext, in map[string
return out
}

func WorkstationClusterNetworkRef_FromProto(mapCtx *direct.MapContext, in string) *refs.ComputeNetworkRef {
if in == "" {
return nil
}
return &refs.ComputeNetworkRef{
External: in,
}
}

func WorkstationClusterSubnetworkRef_FromProto(mapCtx *direct.MapContext, in string) *refs.ComputeSubnetworkRef {
if in == "" {
return nil
}
return &refs.ComputeSubnetworkRef{
External: in,
}
}

func WorkstationCluster_PrivateClusterConfig_FromProto(mapCtx *direct.MapContext, in *pb.WorkstationCluster_PrivateClusterConfig) *krm.WorkstationCluster_PrivateClusterConfig {
if in == nil {
return nil
Expand Down
25 changes: 13 additions & 12 deletions pkg/controller/direct/workstations/workstationcluster_normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ import (
)

func NormalizeWorkstationCluster(ctx context.Context, kube client.Reader, obj *krm.WorkstationCluster) error {
if obj.Spec.NetworkRef != nil {
network, err := refs.ResolveComputeNetwork(ctx, kube, obj, obj.Spec.NetworkRef)
if err != nil {
return err
}
obj.Spec.NetworkRef.External = network.String()
// Resolve network.
network, err := refs.ResolveComputeNetwork(ctx, kube, obj, &obj.Spec.NetworkRef)
if err != nil {
return err
}
if obj.Spec.SubnetworkRef != nil {
subnet, err := refs.ResolveComputeSubnetwork(ctx, kube, obj, obj.Spec.SubnetworkRef)
if err != nil {
return err
}
obj.Spec.SubnetworkRef.External = subnet.External
obj.Spec.NetworkRef.External = network.String()

// Resolve subnetwork.
subnet, err := refs.ResolveComputeSubnetwork(ctx, kube, obj, &obj.Spec.SubnetworkRef)
if err != nil {
return err
}
obj.Spec.SubnetworkRef.External = subnet.External

// Resolve projects (in private cluster config).
if obj.Spec.PrivateClusterConfig != nil && obj.Spec.PrivateClusterConfig.AllowedProjects != nil {
var resolvedProjects []refs.ProjectRef
for _, projectRef := range obj.Spec.PrivateClusterConfig.AllowedProjects {
Expand Down
Loading