Skip to content

Commit

Permalink
Add ImageListPullJob to simplify ImagePullJob
Browse files Browse the repository at this point in the history
Signed-off-by: liuzhenwei <dui_zhang@163.com>

calculate status for imagelistpulljob

Signed-off-by: liuzhenwei <dui_zhang@163.com>

make generate manifests

Signed-off-by: liuzhenwei <dui_zhang@163.com>

add imagelistpulljob.status.status

Signed-off-by: liuzhenwei <dui_zhang@163.com>

make generate manifests

Signed-off-by: liuzhenwei <dui_zhang@163.com>

regist webhook handler

delete image pull job which is not existed in ImageListPullJob.Spec.Images

Signed-off-by: liuzhenwei <dui_zhang@163.com>

support the same behavior as image pull job for TTLSecondsAfterFinished and CompletionTime fields

Signed-off-by: liuzhenwei <dui_zhang@163.com>

resourceVersionExpectations

Signed-off-by: liuzhenwei <dui_zhang@163.com>

add ut

Signed-off-by: liuzhenwei <dui_zhang@163.com>

verify the maximum number of images cannot > 255

Signed-off-by: liuzhenwei <dui_zhang@163.com>

make generate manifests

Signed-off-by: liuzhenwei <dui_zhang@163.com>

add failled image pull job status

Signed-off-by: liuzhenwei <dui_zhang@163.com>

add proposal doc && supoort ImagePullJobTemplate field

Signed-off-by: liuzhenwei <dui_zhang@163.com>
  • Loading branch information
diannaowa committed Mar 27, 2023
1 parent 54079d1 commit 5e4f04a
Show file tree
Hide file tree
Showing 32 changed files with 2,778 additions and 3 deletions.
26 changes: 24 additions & 2 deletions apis/apps/defaults/v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ limitations under the License.
package defaults

import (
appspub "github.com/openkruise/kruise/apis/apps/pub"
"github.com/openkruise/kruise/apis/apps/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
v1 "k8s.io/kubernetes/pkg/apis/core/v1"
utilpointer "k8s.io/utils/pointer"

appspub "github.com/openkruise/kruise/apis/apps/pub"
"github.com/openkruise/kruise/apis/apps/v1alpha1"
)

// SetDefaults_SidecarSet set default values for SidecarSet.
Expand Down Expand Up @@ -365,3 +366,24 @@ func SetDefaultsImagePullJob(obj *v1alpha1.ImagePullJob) {
obj.Spec.PullPolicy.BackoffLimit = utilpointer.Int32Ptr(3)
}
}

// SetDefaultsImageListPullJob set default values for ImageListPullJob.
func SetDefaultsImageListPullJob(obj *v1alpha1.ImageListPullJob) {
if obj.Spec.CompletionPolicy.Type == "" {
obj.Spec.CompletionPolicy.Type = v1alpha1.Always
}
if obj.Spec.PullPolicy == nil {
obj.Spec.PullPolicy = &v1alpha1.PullPolicy{}
}
if obj.Spec.PullPolicy.TimeoutSeconds == nil {
obj.Spec.PullPolicy.TimeoutSeconds = utilpointer.Int32Ptr(600)
}
if obj.Spec.PullPolicy.BackoffLimit == nil {
obj.Spec.PullPolicy.BackoffLimit = utilpointer.Int32Ptr(3)
}
for i, t := range obj.Spec.ImagePullJobTemplate {
if t.CompletionPolicy.Type == "" {
obj.Spec.ImagePullJobTemplate[i].CompletionPolicy.Type = obj.Spec.CompletionPolicy.Type
}
}
}
151 changes: 151 additions & 0 deletions apis/apps/v1alpha1/imagelistpulljob_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
Copyright 2023 The Kruise Authors.
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.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

// ImageListPullJobSpec defines the desired state of ImageListPullJob
type ImageListPullJobSpec struct {

// ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling the image.
// If specified, these secrets will be passed to individual puller implementations for them to use. For example,
// in the case of docker, only DockerConfig type secrets are honored.
// +optional
PullSecrets []string `json:"pullSecrets,omitempty"`

// Selector is a query over nodes that should match the job.
// nil to match all nodes.
// +optional
Selector *ImagePullJobNodeSelector `json:"selector,omitempty"`

// PodSelector is a query over pods that should pull image on nodes of these pods.
// Mutually exclusive with Selector.
// +optional
PodSelector *ImagePullJobPodSelector `json:"podSelector,omitempty"`

// Parallelism is the requested parallelism, it can be set to any non-negative value. If it is unspecified,
// it defaults to 1. If it is specified as 0, then the Job is effectively paused until it is increased.
// +optional
Parallelism *intstr.IntOrString `json:"parallelism,omitempty"`

// PullPolicy is an optional field to set parameters of the pulling task. If not specified,
// the system will use the default values.
// +optional
PullPolicy *PullPolicy `json:"pullPolicy,omitempty"`

// CompletionPolicy indicates the completion policy of the job.
// Default is Always CompletionPolicyType.
CompletionPolicy CompletionPolicy `json:"completionPolicy"`

// SandboxConfig support attach metadata in PullImage CRI interface during ImagePulljobs
// +optional
SandboxConfig *SandboxConfig `json:"sandboxConfig,omitempty"`

// ImagePullJobTemplate imagePullJobSpec list
ImagePullJobTemplate []ImagePullJobSpec `json:"imagePullJobTemplate"`
}

// ImageListPullJobStatus defines the observed state of ImageListPullJob
type ImageListPullJobStatus struct {
// Represents time when the job was acknowledged by the job controller.
// It is not guaranteed to be set in happens-before order across separate operations.
// It is represented in RFC3339 form and is in UTC.
// +optional
StartTime *metav1.Time `json:"startTime,omitempty"`

// Represents time when the all the image pull job was completed. It is not guaranteed to
// be set in happens-before order across separate operations.
// It is represented in RFC3339 form and is in UTC.
// +optional
CompletionTime *metav1.Time `json:"completionTime,omitempty"`

// The desired number of ImagePullJobs, this is typically equal to the number of len(spec.Images).
Desired int32 `json:"desired"`

// The number of actively running ImagePullJobs(status.ACTIVE>0).
// +optional
Active int32 `json:"active"`

// The number of ImagePullJobs which status.CompletionTime!=nil
// +optional
Completed int32 `json:"completed"`

// The number of image pull job which status.Failed==0.
// +optional
Succeeded int32 `json:"succeeded"`

// Succeeded/Completed
// +optional
Status string `json:"status"`

// The status of ImagePullJob which has the failed nodes(status.Failed>0) .
// +optional
FailedImagePullJobStatuses []*FailedImagePullJobStatus `json:"failedImagePullJobStatuses,omitempty"`
}

// FailedImagePullJobStatus the state of ImagePullJob which has the failed nodes(status.Failed>0)
type FailedImagePullJobStatus struct {
// The name of ImagePullJob which has the failed nodes(status.Failed>0)
// +optional
Name string `json:"name,omitempty"`

// Image is the image to be pulled by the job
// +optional
Image string `json:"image,omitempty"`

// The number of pulling tasks which reached phase Failed of this ImagePullJob.
// +optional
Failed int32 `json:"failed,omitempty"`

// The nodes that failed to pull the image of this ImagePullJob.
// +optional
FailedNodes []string `json:"failedNodes,omitempty"`
}

// +genclient
// +k8s:openapi-gen=true
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="TOTAL",type="integer",JSONPath=".status.desired",description="Number of image pull job"
// +kubebuilder:printcolumn:name="ACTIVE",type="integer",JSONPath=".status.active",description="Number of image pull job active"
// +kubebuilder:printcolumn:name="STATUS",type="string",JSONPath=".status.status",description="status.succeeded/status.completed"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp",description="CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC."

// ImageListPullJob is the Schema for the imagelistpulljobs API
type ImageListPullJob struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ImageListPullJobSpec `json:"spec,omitempty"`
Status ImageListPullJobStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// ImageListPullJobList contains a list of ImageListPullJob
type ImageListPullJobList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ImageListPullJob `json:"items"`
}

func init() {
SchemeBuilder.Register(&ImageListPullJob{}, &ImageListPullJobList{})
}
1 change: 1 addition & 0 deletions apis/apps/v1alpha1/imagepulljob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
ImagePreDownloadParallelismKey = "apps.kruise.io/image-predownload-parallelism"
ImagePreDownloadTimeoutSecondsKey = "apps.kruise.io/image-predownload-timeout-seconds"
ImagePreDownloadMinUpdatedReadyPods = "apps.kruise.io/image-predownload-min-updated-ready-pods"
ImagePullJobTemplateHashKey = "apps.kruise.io/imagepulljob-template-hash"
)

// ImagePullJobSpec defines the desired state of ImagePullJob
Expand Down
166 changes: 166 additions & 0 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 5e4f04a

Please sign in to comment.