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>
  • Loading branch information
diannaowa committed Mar 15, 2023
1 parent 54079d1 commit 6c39669
Show file tree
Hide file tree
Showing 28 changed files with 2,141 additions and 0 deletions.
16 changes: 16 additions & 0 deletions apis/apps/defaults/v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,19 @@ 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)
}
}
127 changes: 127 additions & 0 deletions apis/apps/v1alpha1/imagelistpulljob_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
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 {
// Images is the image list to be pulled by the job
Images []string `json:"images"`

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

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

// +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{})
}
133 changes: 133 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 6c39669

Please sign in to comment.