Optimize startup and cleanup for v1beta1 apis (#434)

Signed-off-by: Siyu Wang <FillZpp.pub@gmail.com>
This commit is contained in:
Siyu Wang 2020-11-04 14:50:08 +08:00 committed by GitHub
parent 0b291b5f6e
commit dbf1cad054
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 65 additions and 36 deletions

View File

@ -0,0 +1,31 @@
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}"
namespace: kruise-system
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
annotations:
# This is what defines this resource as a hook. Without this line, the
# job is considered part of the release.
"helm.sh/hook": pre-delete
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
metadata:
name: "{{ .Release.Name }}"
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
restartPolicy: Never
containers:
- name: post-install-job
image: "appscode/kubectl:v1.18"
command: ["bin/sh", "-c"]
args:
- /usr/bin/kubectl get crd -o name | grep customresourcedefinition.apiextensions.k8s.io/[a-z.]*.kruise.io | xargs kubectl patch -p '{"spec":{"conversion":null}}'

20
main.go
View File

@ -127,12 +127,6 @@ func main() {
os.Exit(1)
}
setupLog.Info("setup controllers")
if err = controller.SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to setup controllers")
os.Exit(1)
}
setupLog.Info("setup webhook")
if err = webhook.SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to setup webhook")
@ -153,6 +147,20 @@ func main() {
os.Exit(1)
}
go func() {
setupLog.Info("wait webhook ready")
if err = webhook.WaitReady(); err != nil {
setupLog.Error(err, "unable to wait webhook ready")
os.Exit(1)
}
setupLog.Info("setup controllers")
if err = controller.SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to setup controllers")
os.Exit(1)
}
}()
setupLog.Info("starting manager")
if err := mgr.Start(stopCh); err != nil {
setupLog.Error(err, "problem running manager")

View File

@ -17,16 +17,11 @@ limitations under the License.
package webhook
import (
appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
"github.com/openkruise/kruise/pkg/util/gate"
"github.com/openkruise/kruise/pkg/webhook/broadcastjob/mutating"
"github.com/openkruise/kruise/pkg/webhook/broadcastjob/validating"
)
func init() {
if !gate.ResourceEnabled(&appsv1alpha1.BroadcastJob{}) {
return
}
addHandlers(mutating.HandlerMap)
addHandlers(validating.HandlerMap)
}

View File

@ -17,16 +17,11 @@ limitations under the License.
package webhook
import (
appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
"github.com/openkruise/kruise/pkg/util/gate"
"github.com/openkruise/kruise/pkg/webhook/cloneset/mutating"
"github.com/openkruise/kruise/pkg/webhook/cloneset/validating"
)
func init() {
if !gate.ResourceEnabled(&appsv1alpha1.CloneSet{}) {
return
}
addHandlers(mutating.HandlerMap)
addHandlers(validating.HandlerMap)
}

View File

@ -17,14 +17,9 @@ limitations under the License.
package webhook
import (
appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
"github.com/openkruise/kruise/pkg/util/gate"
"github.com/openkruise/kruise/pkg/webhook/daemonset/mutating"
)
func init() {
if !gate.ResourceEnabled(&appsv1alpha1.DaemonSet{}) {
return
}
addHandlers(mutating.HandlerMap)
}

View File

@ -17,16 +17,11 @@ limitations under the License.
package webhook
import (
appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
"github.com/openkruise/kruise/pkg/util/gate"
"github.com/openkruise/kruise/pkg/webhook/sidecarset/mutating"
"github.com/openkruise/kruise/pkg/webhook/sidecarset/validating"
)
func init() {
if !gate.ResourceEnabled(&appsv1alpha1.SidecarSet{}) {
return
}
addHandlers(mutating.HandlerMap)
addHandlers(validating.HandlerMap)
}

View File

@ -17,16 +17,11 @@ limitations under the License.
package webhook
import (
appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
"github.com/openkruise/kruise/pkg/util/gate"
"github.com/openkruise/kruise/pkg/webhook/statefulset/mutating"
"github.com/openkruise/kruise/pkg/webhook/statefulset/validating"
)
func init() {
if !gate.ResourceEnabled(&appsv1alpha1.StatefulSet{}) {
return
}
addHandlers(mutating.HandlerMap)
addHandlers(validating.HandlerMap)
}

View File

@ -17,16 +17,11 @@ limitations under the License.
package webhook
import (
appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
"github.com/openkruise/kruise/pkg/util/gate"
"github.com/openkruise/kruise/pkg/webhook/uniteddeployment/mutating"
"github.com/openkruise/kruise/pkg/webhook/uniteddeployment/validating"
)
func init() {
if !gate.ResourceEnabled(&appsv1alpha1.UnitedDeployment{}) {
return
}
addHandlers(mutating.HandlerMap)
addHandlers(validating.HandlerMap)
}

View File

@ -105,3 +105,23 @@ func Initialize(mgr manager.Manager, stopCh <-chan struct{}) error {
return fmt.Errorf("failed to start webhook controller for waiting more than 5s")
}
}
func WaitReady() error {
startTS := time.Now()
var err error
for {
duration := time.Since(startTS)
if err = Checker(nil); err == nil {
return nil
}
if duration > time.Second*5 {
klog.Warningf("Failed to wait webhook ready over %s: %v", duration, err)
}
if duration > time.Minute {
return err
}
time.Sleep(time.Second * 2)
}
}