Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
39 changes: 39 additions & 0 deletions apis/batch/v1alpha1/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
# 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.


set -o errexit
set -o nounset
set -o pipefail

REPO_ROOT="$(git rev-parse --show-toplevel)"
cd ${REPO_ROOT}/dev/tools/controllerbuilder

go run . generate-types \
--service google.cloud.batch.v1 \
--api-version "batch.cnrm.cloud.google.com/v1alpha1" \
--resource BatchJob:Job \
--resource BatchTask:Task


go run . generate-mapper \
--service google.cloud.batch.v1 \
--api-version "batch.cnrm.cloud.google.com/v1alpha1"

cd ${REPO_ROOT}
dev/tasks/generate-crds

go run -mod=readonly golang.org/x/tools/cmd/goimports@latest -w pkg/controller/direct/batch/

6 changes: 3 additions & 3 deletions apis/batch/v1alpha1/job_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ type BatchJobSpec struct {
// Batch, see
// [Organize resources using
// labels](https://cloud.google.com/batch/docs/organize-resources-using-labels).
// +kcc:proto:field=google.cloud.batch.v1.Job.labels
Labels map[string]string `json:"labels,omitempty"`
// +k_cc:proto:field=google.cloud.batch.v1.Job.labels
// Labels map[string]string `json:"labels,omitempty"`

// Log preservation policy for the Job.
// +kcc:proto:field=google.cloud.batch.v1.Job.logs_policy
Expand Down Expand Up @@ -161,7 +161,7 @@ type AllocationPolicy_Disk struct {
// * `batch-cos`: use Batch Container-Optimized images.
// * `batch-hpc-rocky`: use Batch HPC Rocky Linux images.
// +kcc:proto:field=google.cloud.batch.v1.AllocationPolicy.Disk.image
ImageRef *v1alpha1.ResourceRef `json:"imageRef,omitempty"`
Image *string `json:"image,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like an imageRef?


// Name of a snapshot used as the data source.
// Snapshot is not supported as boot disk now.
Expand Down
31 changes: 19 additions & 12 deletions apis/batch/v1alpha1/types.generated.go

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

13 changes: 3 additions & 10 deletions apis/batch/v1alpha1/zz_generated.deepcopy.go

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.

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/common"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/directbase"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/registry"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/label"
"github.com/golang/protobuf/proto"
)

Expand Down Expand Up @@ -100,6 +101,8 @@ func (m *jobModel) AdapterForObject(ctx context.Context, reader client.Reader, u
return nil, err
}

desired.Labels = label.NewGCPLabelsFromK8sLabels(u.GetLabels())

gcpClient, err := m.Client(ctx, id.Parent().ProjectID)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/direct/batch/job_fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func batchJobFuzzer() fuzztesting.KRMFuzzer {
f.StatusFields.Insert(".task_groups")
f.StatusFields.Insert(".status")

f.Unimplemented_LabelsAnnotations(".labels")
f.UnimplementedFields.Insert(".allocation_policy.service_account.scopes")
f.UnimplementedFields.Insert(".status.task_groups")

Expand Down
63 changes: 63 additions & 0 deletions pkg/controller/direct/batch/job_mapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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.

// +generated:mapper
// krm.group: batch.cnrm.cloud.google.com
// krm.version: v1alpha1
// proto.service: google.cloud.batch.v1

package batch

import (
pb "cloud.google.com/go/batch/apiv1/batchpb"
krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/batch/v1alpha1"
refsv1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct"
)

func AllocationPolicy_FromProto(mapCtx *direct.MapContext, in *pb.AllocationPolicy) *krm.AllocationPolicy {
if in == nil {
return nil
}
out := &krm.AllocationPolicy{}
out.Location = AllocationPolicy_LocationPolicy_FromProto(mapCtx, in.GetLocation())
out.Instances = direct.Slice_FromProto(mapCtx, in.Instances, AllocationPolicy_InstancePolicyOrTemplate_FromProto)

if in.GetServiceAccount() != nil {
out.ServiceAccountRef = &refsv1beta1.IAMServiceAccountRef{External: in.GetServiceAccount().Email}
}
out.Labels = in.Labels
out.Network = AllocationPolicy_NetworkPolicy_FromProto(mapCtx, in.GetNetwork())
out.Placement = AllocationPolicy_PlacementPolicy_FromProto(mapCtx, in.GetPlacement())
out.Tags = in.Tags
return out
}
func AllocationPolicy_ToProto(mapCtx *direct.MapContext, in *krm.AllocationPolicy) *pb.AllocationPolicy {
if in == nil {
return nil
}
out := &pb.AllocationPolicy{}
out.Location = AllocationPolicy_LocationPolicy_ToProto(mapCtx, in.Location)
out.Instances = direct.Slice_ToProto(mapCtx, in.Instances, AllocationPolicy_InstancePolicyOrTemplate_ToProto)
if in.ServiceAccountRef != nil {
out.ServiceAccount = &pb.ServiceAccount{
Email: in.ServiceAccountRef.External,
}
}
out.Labels = in.Labels
out.Network = AllocationPolicy_NetworkPolicy_ToProto(mapCtx, in.Network)
out.Placement = AllocationPolicy_PlacementPolicy_ToProto(mapCtx, in.Placement)
out.Tags = in.Tags
return out
}
Loading