Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add imagepulljob featuregate #1357

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ var (
// Add creates a new ImageListPullJob Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(mgr manager.Manager) error {
if !utildiscovery.DiscoverGVK(controllerKind) || !utilfeature.DefaultFeatureGate.Enabled(features.KruiseDaemon) {
if !utildiscovery.DiscoverGVK(controllerKind) || !utilfeature.DefaultFeatureGate.Enabled(features.KruiseDaemon) ||
!utilfeature.DefaultFeatureGate.Enabled(features.ImagePullJobGate) {
return nil
}
return add(mgr, newReconciler(mgr))
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/imagepulljob/imagepulljob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ const (
// Add creates a new ImagePullJob Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(mgr manager.Manager) error {
if !utildiscovery.DiscoverGVK(controllerKind) || !utilfeature.DefaultFeatureGate.Enabled(features.KruiseDaemon) {
if !utildiscovery.DiscoverGVK(controllerKind) || !utilfeature.DefaultFeatureGate.Enabled(features.KruiseDaemon) ||
!utilfeature.DefaultFeatureGate.Enabled(features.ImagePullJobGate) {
return nil
}
return add(mgr, newReconciler(mgr))
Expand Down
8 changes: 8 additions & 0 deletions pkg/features/kruise_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ const (
// PreparingUpdateAsUpdate enable CloneSet/Advanced StatefulSet controller to regard preparing-update Pod
// as updated when calculating update/current revision during scaling.
PreparingUpdateAsUpdate featuregate.Feature = "PreparingUpdateAsUpdate"

// ImagePullJobGate enable imagepulljob-controller execute ImagePullJob.
ImagePullJobGate featuregate.Feature = "ImagePullJobGate"
)

var defaultFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
Expand All @@ -129,6 +132,7 @@ var defaultFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
PreDownloadImageForDaemonSetUpdate: {Default: false, PreRelease: featuregate.Alpha},
CloneSetEventHandlerOptimization: {Default: false, PreRelease: featuregate.Alpha},
PreparingUpdateAsUpdate: {Default: false, PreRelease: featuregate.Alpha},
ImagePullJobGate: {Default: false, PreRelease: featuregate.Alpha},
}

func init() {
Expand Down Expand Up @@ -164,5 +168,9 @@ func SetDefaultFeatureGates() {
_ = utilfeature.DefaultMutableFeatureGate.Set(fmt.Sprintf("%s=false", PreDownloadImageForDaemonSetUpdate))
_ = utilfeature.DefaultMutableFeatureGate.Set(fmt.Sprintf("%s=false", PodProbeMarkerGate))
_ = utilfeature.DefaultMutableFeatureGate.Set(fmt.Sprintf("%s=false", SidecarTerminator))
_ = utilfeature.DefaultMutableFeatureGate.Set(fmt.Sprintf("%s=false", ImagePullJobGate))
}
if utilfeature.DefaultFeatureGate.Enabled(PreDownloadImageForInPlaceUpdate) || utilfeature.DefaultFeatureGate.Enabled(PreDownloadImageForDaemonSetUpdate) {
_ = utilfeature.DefaultMutableFeatureGate.Set(fmt.Sprintf("%s=true", ImagePullJobGate))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func (h *ImageListPullJobCreateUpdateHandler) Handle(ctx context.Context, req ad
if !utilfeature.DefaultFeatureGate.Enabled(features.KruiseDaemon) {
return admission.Errored(http.StatusForbidden, fmt.Errorf("feature-gate %s is not enabled", features.KruiseDaemon))
}
if !utilfeature.DefaultFeatureGate.Enabled(features.ImagePullJobGate) {
return admission.Errored(http.StatusForbidden, fmt.Errorf("feature-gate %s is not enabled", features.ImagePullJobGate))
}

if err := validate(obj); err != nil {
klog.Warningf("Error validate ImageListPullJob %s/%s: %v", obj.Namespace, obj.Name, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func (h *ImagePullJobCreateUpdateHandler) Handle(ctx context.Context, req admiss
if !utilfeature.DefaultFeatureGate.Enabled(features.KruiseDaemon) {
return admission.Errored(http.StatusForbidden, fmt.Errorf("feature-gate %s is not enabled", features.KruiseDaemon))
}
if !utilfeature.DefaultFeatureGate.Enabled(features.ImagePullJobGate) {
return admission.Errored(http.StatusForbidden, fmt.Errorf("feature-gate %s is not enabled", features.ImagePullJobGate))
}

if err := validate(obj); err != nil {
klog.Warningf("Error validate ImagePullJob %s/%s: %v", obj.Namespace, obj.Name, err)
Expand Down
17 changes: 15 additions & 2 deletions test/e2e/apps/pullimages.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package apps

import (
"context"
"fmt"
"time"

Expand Down Expand Up @@ -108,11 +109,23 @@ var _ = SIGDescribe("PullImage", func() {
ActiveDeadlineSeconds: utilpointer.Int64Ptr(50),
TTLSecondsAfterFinished: utilpointer.Int32Ptr(20),
},
PullSecrets: []string{"test-pull-secret"},
},
}
err := testerForImagePullJob.CreateJob(job)
secret := &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: "test-pull-secret",
},
Type: v1.SecretTypeDockercfg,
Data: map[string][]byte{
v1.DockerConfigKey: []byte(`{"auths":{"docker.io/library/nginx":{"username":"echoserver","password":"test","auth":"ZWNob3NlcnZlcjp0ZXN0"}}}`),
},
}
_, err := c.CoreV1().Secrets(ns).Create(context.TODO(), secret, metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
err = testerForImagePullJob.CreateJob(job)
gomega.Expect(err).NotTo(gomega.HaveOccurred())

ginkgo.By("Desired should be equal to number of nodes")
gomega.Eventually(func() int32 {
job, err = testerForImagePullJob.GetJob(job)
Expand Down
Loading