Skip to content

Commit aec3323

Browse files
authored
Merge branch 'master' into feature/add-if-not-exists-action
2 parents 7fa7fdf + 3c015e0 commit aec3323

File tree

74 files changed

+1273
-298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1273
-298
lines changed

.github/workflows/lint-sample.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- name: Run linter
4444
uses: golangci/golangci-lint-action@v8
4545
with:
46-
version: v2.2.2
46+
version: v2.3.0
4747
working-directory: ${{ matrix.folder }}
4848
- name: Run linter via makefile target
4949
working-directory: ${{ matrix.folder }}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ yamllint:
127127
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
128128
golangci-lint:
129129
@[ -f $(GOLANGCI_LINT) ] || { \
130-
GOBIN=$(shell pwd)/bin go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.2.2 ;\
130+
GOBIN=$(shell pwd)/bin go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.3.0 ;\
131131
}
132132

133133
.PHONY: apidiff

cmd/cmd.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ limitations under the License.
1717
package cmd
1818

1919
import (
20-
"github.com/sirupsen/logrus"
20+
"log"
21+
"log/slog"
22+
"os"
23+
2124
"github.com/spf13/afero"
2225

2326
"sigs.k8s.io/kubebuilder/v4/pkg/cli"
2427
cfgv3 "sigs.k8s.io/kubebuilder/v4/pkg/config/v3"
28+
"sigs.k8s.io/kubebuilder/v4/pkg/logging"
2529
"sigs.k8s.io/kubebuilder/v4/pkg/machinery"
2630
"sigs.k8s.io/kubebuilder/v4/pkg/plugin"
2731
kustomizecommonv2 "sigs.k8s.io/kubebuilder/v4/pkg/plugins/common/kustomize/v2"
@@ -33,8 +37,14 @@ import (
3337
)
3438

3539
func init() {
36-
// Disable timestamps on the default TextFormatter
37-
logrus.SetFormatter(&logrus.TextFormatter{DisableTimestamp: true})
40+
opts := logging.HandlerOptions{
41+
SlogOpts: slog.HandlerOptions{
42+
Level: slog.LevelInfo,
43+
},
44+
}
45+
handler := logging.NewHandler(os.Stdout, opts)
46+
logger := slog.New(handler)
47+
slog.SetDefault(logger)
3848
}
3949

4050
// Run bootstraps & runs the CLI
@@ -50,7 +60,7 @@ func Run() {
5060
}
5161
externalPlugins, err := cli.DiscoverExternalPlugins(fs.FS)
5262
if err != nil {
53-
logrus.Error(err)
63+
slog.Error("error discovering external plugins", "error", err)
5464
}
5565

5666
c, err := cli.New(
@@ -71,9 +81,9 @@ func Run() {
7181
cli.WithCompletion(),
7282
)
7383
if err != nil {
74-
logrus.Fatal(err)
84+
log.Fatal(err)
7585
}
7686
if err := c.Run(); err != nil {
77-
logrus.Fatal(err)
87+
log.Fatal(err)
7888
}
7989
}

docs/book/install-and-build.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ if [[ ${arch} == "amd64" ]]; then
3838
arch="x86_64"
3939
elif [[ ${arch} == "x86" ]]; then
4040
arch="i686"
41+
elif [[ ${arch} == "arm64" ]]; then
42+
# arm64 is not supported for v0.4.40 mdbook, so using x86_64 type.
43+
# Once the mdbook is upgraded to latest, use 'aarch64'
44+
arch="x86_64"
4145
fi
4246

4347
# translate os to rust's conventions (if we can)
@@ -63,15 +67,21 @@ esac
6367

6468
# grab mdbook
6569
# we hardcode linux/amd64 since rust uses a different naming scheme and it's a pain to tran
66-
echo "downloading mdBook-v0.4.40-${arch}-${target}.${ext}"
70+
MDBOOK_VERSION="v0.4.40"
71+
MDBOOK_BASENAME="mdBook-${MDBOOK_VERSION}-${arch}-${target}"
72+
MDBOOK_URL="https://github.com/rust-lang/mdBook/releases/download/${MDBOOK_VERSION}/${MDBOOK_BASENAME}.${ext}"
73+
74+
echo "downloading ${MDBOOK_BASENAME}.${ext} from ${MDBOOK_URL}"
6775
set -x
68-
curl -sL -o /tmp/mdbook.${ext} https://github.com/rust-lang/mdBook/releases/download/v0.4.40/mdBook-v0.4.40-${arch}-${target}.${ext}
76+
curl -fL -o /tmp/mdbook.${ext} "${MDBOOK_URL}"
6977
${cmd} /tmp/mdbook.${ext}
7078
chmod +x /tmp/mdbook
7179

72-
echo "grabbing the latest released controller-gen"
80+
CONTROLLER_GEN_VERSION="v0.18.0"
81+
82+
echo "grabbing the controller-gen version: ${CONTROLLER_GEN_VERSION}"
7383
go version
74-
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.18.0
84+
go install sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_GEN_VERSION}
7585

7686
# make sure we add the go bin directory to our path
7787
gobin=$(go env GOBIN)

docs/book/src/cronjob-tutorial/testdata/project/api/v1/cronjob_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ type CronJobSpec struct {
8181
// - "Forbid": forbids concurrent runs, skipping next run if previous run hasn't finished yet;
8282
// - "Replace": cancels currently running job and replaces it with a new one
8383
// +optional
84+
// +kubebuilder:default:=Allow
8485
ConcurrencyPolicy ConcurrencyPolicy `json:"concurrencyPolicy,omitempty"`
8586

8687
// suspend tells the controller to suspend subsequent executions, it does
@@ -89,6 +90,7 @@ type CronJobSpec struct {
8990
Suspend *bool `json:"suspend,omitempty"`
9091

9192
// jobTemplate defines the job that will be created when executing a CronJob.
93+
// +required
9294
JobTemplate batchv1.JobTemplateSpec `json:"jobTemplate"`
9395

9496
// successfulJobsHistoryLimit defines the number of successful finished jobs to retain.
@@ -146,6 +148,9 @@ type CronJobStatus struct {
146148

147149
// active defines a list of pointers to currently running jobs.
148150
// +optional
151+
// +listType=atomic
152+
// +kubebuilder:validation:MinItems=1
153+
// +kubebuilder:validation:MaxItems=10
149154
Active []corev1.ObjectReference `json:"active,omitempty"`
150155

151156
// lastScheduleTime defines when was the last time the job was successfully scheduled.

docs/book/src/cronjob-tutorial/testdata/project/config/crd/bases/batch.tutorial.kubebuilder.io_cronjobs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ spec:
2727
spec:
2828
properties:
2929
concurrencyPolicy:
30+
default: Allow
3031
enum:
3132
- Allow
3233
- Forbid
@@ -3835,7 +3836,10 @@ spec:
38353836
type: string
38363837
type: object
38373838
x-kubernetes-map-type: atomic
3839+
maxItems: 10
3840+
minItems: 1
38383841
type: array
3842+
x-kubernetes-list-type: atomic
38393843
conditions:
38403844
items:
38413845
properties:

docs/book/src/cronjob-tutorial/testdata/project/dist/chart/templates/crd/batch.tutorial.kubebuilder.io_cronjobs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ spec:
3333
spec:
3434
properties:
3535
concurrencyPolicy:
36+
default: Allow
3637
enum:
3738
- Allow
3839
- Forbid
@@ -3841,7 +3842,10 @@ spec:
38413842
type: string
38423843
type: object
38433844
x-kubernetes-map-type: atomic
3845+
maxItems: 10
3846+
minItems: 1
38443847
type: array
3848+
x-kubernetes-list-type: atomic
38453849
conditions:
38463850
items:
38473851
properties:

docs/book/src/cronjob-tutorial/testdata/project/dist/install.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ spec:
3535
spec:
3636
properties:
3737
concurrencyPolicy:
38+
default: Allow
3839
enum:
3940
- Allow
4041
- Forbid
@@ -3843,7 +3844,10 @@ spec:
38433844
type: string
38443845
type: object
38453846
x-kubernetes-map-type: atomic
3847+
maxItems: 10
3848+
minItems: 1
38463849
type: array
3850+
x-kubernetes-list-type: atomic
38473851
conditions:
38483852
items:
38493853
properties:

docs/book/src/cronjob-tutorial/testdata/project/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
k8s.io/api v0.33.0
1010
k8s.io/apimachinery v0.33.0
1111
k8s.io/client-go v0.33.0
12+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
1213
sigs.k8s.io/controller-runtime v0.21.0
1314
)
1415

@@ -89,7 +90,6 @@ require (
8990
k8s.io/component-base v0.33.0 // indirect
9091
k8s.io/klog/v2 v2.130.1 // indirect
9192
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
92-
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
9393
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 // indirect
9494
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
9595
sigs.k8s.io/randfill v1.0.0 // indirect

docs/book/src/cronjob-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
batchv1 "tutorial.kubebuilder.io/project/api/v1"
2424
// TODO (user): Add any additional imports if needed
25+
"k8s.io/utils/ptr"
2526
)
2627

2728
var _ = Describe("CronJob Webhook", func() {
@@ -40,8 +41,8 @@ var _ = Describe("CronJob Webhook", func() {
4041
Spec: batchv1.CronJobSpec{
4142
Schedule: schedule,
4243
ConcurrencyPolicy: batchv1.AllowConcurrent,
43-
SuccessfulJobsHistoryLimit: new(int32),
44-
FailedJobsHistoryLimit: new(int32),
44+
SuccessfulJobsHistoryLimit: ptr.To(int32(3)),
45+
FailedJobsHistoryLimit: ptr.To(int32(1)),
4546
},
4647
}
4748
*obj.Spec.SuccessfulJobsHistoryLimit = 3
@@ -51,8 +52,8 @@ var _ = Describe("CronJob Webhook", func() {
5152
Spec: batchv1.CronJobSpec{
5253
Schedule: schedule,
5354
ConcurrencyPolicy: batchv1.AllowConcurrent,
54-
SuccessfulJobsHistoryLimit: new(int32),
55-
FailedJobsHistoryLimit: new(int32),
55+
SuccessfulJobsHistoryLimit: ptr.To(int32(3)),
56+
FailedJobsHistoryLimit: ptr.To(int32(1)),
5657
},
5758
}
5859
*oldObj.Spec.SuccessfulJobsHistoryLimit = 3
@@ -95,20 +96,20 @@ var _ = Describe("CronJob Webhook", func() {
9596
It("Should not overwrite fields that are already set", func() {
9697
By("setting fields that would normally get a default")
9798
obj.Spec.ConcurrencyPolicy = batchv1.ForbidConcurrent
98-
obj.Spec.Suspend = new(bool)
99-
*obj.Spec.Suspend = true
100-
obj.Spec.SuccessfulJobsHistoryLimit = new(int32)
101-
*obj.Spec.SuccessfulJobsHistoryLimit = 5
102-
obj.Spec.FailedJobsHistoryLimit = new(int32)
103-
*obj.Spec.FailedJobsHistoryLimit = 2
99+
obj.Spec.Suspend = ptr.To(true)
100+
obj.Spec.SuccessfulJobsHistoryLimit = ptr.To(int32(5))
101+
obj.Spec.FailedJobsHistoryLimit = ptr.To(int32(2))
104102

105103
By("calling the Default method to apply defaults")
106104
_ = defaulter.Default(ctx, obj)
107105

108106
By("checking that the fields were not overwritten")
109107
Expect(obj.Spec.ConcurrencyPolicy).To(Equal(batchv1.ForbidConcurrent), "Expected ConcurrencyPolicy to retain its set value")
108+
Expect(obj.Spec.Suspend).NotTo(BeNil())
110109
Expect(*obj.Spec.Suspend).To(BeTrue(), "Expected Suspend to retain its set value")
110+
Expect(obj.Spec.SuccessfulJobsHistoryLimit).NotTo(BeNil())
111111
Expect(*obj.Spec.SuccessfulJobsHistoryLimit).To(Equal(int32(5)), "Expected SuccessfulJobsHistoryLimit to retain its set value")
112+
Expect(obj.Spec.FailedJobsHistoryLimit).NotTo(BeNil())
112113
Expect(*obj.Spec.FailedJobsHistoryLimit).To(Equal(int32(2)), "Expected FailedJobsHistoryLimit to retain its set value")
113114
})
114115
})

0 commit comments

Comments
 (0)