Skip to content

Commit

Permalink
fix: Make WorkstationCluster network/subnetwork required
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvigil committed Sep 30, 2024
1 parent 93278d7 commit 0a94ca5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 63 deletions.
4 changes: 2 additions & 2 deletions apis/workstations/v1alpha1/workstationcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ 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"`
NetworkRef refs.ComputeNetworkRef `json:"networkRef"`

// 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"`
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
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

0 comments on commit 0a94ca5

Please sign in to comment.