Skip to content

Commit 82f6db3

Browse files
authored
Merge pull request #4 from cybozu-go/add-imageprefetch-crd
Create a template for the ImagePrefetch CRD
2 parents 65c7bd4 + cb87eb7 commit 82f6db3

20 files changed

+772
-45
lines changed

PROJECT

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
domain: ofen.cybozu.io
1+
domain: cybozu.io
22
layout:
33
- go.kubebuilder.io/v4
44
projectName: ofen
55
repo: github.com/cybozu-go/ofen
6+
resources:
7+
- api:
8+
crdVersion: v1
9+
namespaced: true
10+
controller: true
11+
domain: cybozu.io
12+
group: ofen
13+
kind: ImagePrefetch
14+
path: github.com/cybozu-go/ofen/api/v1
15+
version: v1
616
version: "3"

api/v1/groupversion_info.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Package v1 contains API Schema definitions for the ofen v1 API group
2+
// +kubebuilder:object:generate=true
3+
// +groupName=ofen.cybozu.io
4+
package v1
5+
6+
import (
7+
"k8s.io/apimachinery/pkg/runtime/schema"
8+
"sigs.k8s.io/controller-runtime/pkg/scheme"
9+
)
10+
11+
var (
12+
// GroupVersion is group version used to register these objects
13+
GroupVersion = schema.GroupVersion{Group: "ofen.cybozu.io", Version: "v1"}
14+
15+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
16+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
17+
18+
// AddToScheme adds the types in this group-version to the given scheme.
19+
AddToScheme = SchemeBuilder.AddToScheme
20+
)

api/v1/imageprefetch_types.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package v1
2+
3+
import (
4+
corev1 "k8s.io/api/core/v1"
5+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6+
)
7+
8+
// ImagePrefetchSpec defines the desired state of ImagePrefetch
9+
type ImagePrefetchSpec struct {
10+
// Images is a list of container images that will be pre-downloaded to the target nodes
11+
Images []string `json:"images"`
12+
13+
// NodeSelector is a map of key-value pairs that specify which nodes should have the images pre-downloaded
14+
// +optional
15+
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
16+
17+
// Replicas is the number of nodes that should download the specified images
18+
// +optional
19+
Replicas int `json:"replicas,omitempty"`
20+
21+
// ImagePullSecrets is a list of secret names that contain credentials for authenticating with container registries
22+
// +optional
23+
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
24+
}
25+
26+
// ImagePrefetchStatus defines the observed state of ImagePrefetch
27+
type ImagePrefetchStatus struct {
28+
// The generation observed by the controller.
29+
// +optional
30+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
31+
32+
// Conditions represent the latest available observations of an object's state
33+
// +listType=map
34+
// +listMapKey=type
35+
// +optional
36+
Conditions []metav1.Condition `json:"conditions,omitempty"`
37+
38+
// DesiredNodes represents the number of nodes that should have the images pre-downloaded
39+
// +optional
40+
// +kubebuilder:default:=0
41+
DesiredNodes int `json:"desiredNodes,omitempty"`
42+
43+
// ImagePulledNodes represents the number of nodes that have successfully pre-downloaded the images
44+
// +optional
45+
// +kubebuilder:default:=0
46+
ImagePulledNodes int `json:"imagePulledNodes,omitempty"`
47+
48+
// ImagePullingNodes represents the number of nodes that are currently downloading the images
49+
// +optional
50+
// +kubebuilder:default:=0
51+
ImagePullingNodes int `json:"imagePullingNodes,omitempty"`
52+
53+
// ImagePullFailedNodes represents the number of nodes that failed to download the images
54+
// +optional
55+
// +kubebuilder:default:=0
56+
ImagePullFailedNodes int `json:"imagePullFailedNodes,omitempty"`
57+
}
58+
59+
const (
60+
ConditionReady = "Ready"
61+
ConditionProgressing = "Progressing"
62+
ConditionImageDownloadFailed = "ImageDownloadFailed"
63+
)
64+
65+
// +kubebuilder:object:root=true
66+
// +kubebuilder:subresource:status
67+
68+
// ImagePrefetch is the Schema for the imageprefetches API
69+
type ImagePrefetch struct {
70+
metav1.TypeMeta `json:",inline"`
71+
metav1.ObjectMeta `json:"metadata,omitempty"`
72+
73+
Spec ImagePrefetchSpec `json:"spec,omitempty"`
74+
Status ImagePrefetchStatus `json:"status,omitempty"`
75+
}
76+
77+
// +kubebuilder:object:root=true
78+
79+
// ImagePrefetchList contains a list of ImagePrefetch
80+
type ImagePrefetchList struct {
81+
metav1.TypeMeta `json:",inline"`
82+
metav1.ListMeta `json:"metadata,omitempty"`
83+
Items []ImagePrefetch `json:"items"`
84+
}
85+
86+
func init() {
87+
SchemeBuilder.Register(&ImagePrefetch{}, &ImagePrefetchList{})
88+
}

api/v1/zz_generated.deepcopy.go

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/main.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
/*
2-
Copyright 2025.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
16-
171
package main
182

193
import (
@@ -32,6 +16,9 @@ import (
3216
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
3317
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3418
"sigs.k8s.io/controller-runtime/pkg/webhook"
19+
20+
ofenv1 "github.com/cybozu-go/ofen/api/v1"
21+
"github.com/cybozu-go/ofen/internal/controller"
3522
// +kubebuilder:scaffold:imports
3623
)
3724

@@ -43,6 +30,7 @@ var (
4330
func init() {
4431
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
4532

33+
utilruntime.Must(ofenv1.AddToScheme(scheme))
4634
// +kubebuilder:scaffold:scheme
4735
}
4836

@@ -138,6 +126,13 @@ func main() {
138126
os.Exit(1)
139127
}
140128

129+
if err = (&controller.ImagePrefetchReconciler{
130+
Client: mgr.GetClient(),
131+
Scheme: mgr.GetScheme(),
132+
}).SetupWithManager(mgr); err != nil {
133+
setupLog.Error(err, "unable to create controller", "controller", "ImagePrefetch")
134+
os.Exit(1)
135+
}
141136
// +kubebuilder:scaffold:builder
142137

143138
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {

0 commit comments

Comments
 (0)