mirror of https://github.com/openkruise/kruise.git
Optimize startup and cleanup for v1beta1 apis (#434)
Signed-off-by: Siyu Wang <FillZpp.pub@gmail.com>
This commit is contained in:
parent
0b291b5f6e
commit
dbf1cad054
|
@ -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
20
main.go
|
@ -127,12 +127,6 @@ func main() {
|
||||||
os.Exit(1)
|
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")
|
setupLog.Info("setup webhook")
|
||||||
if err = webhook.SetupWithManager(mgr); err != nil {
|
if err = webhook.SetupWithManager(mgr); err != nil {
|
||||||
setupLog.Error(err, "unable to setup webhook")
|
setupLog.Error(err, "unable to setup webhook")
|
||||||
|
@ -153,6 +147,20 @@ func main() {
|
||||||
os.Exit(1)
|
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")
|
setupLog.Info("starting manager")
|
||||||
if err := mgr.Start(stopCh); err != nil {
|
if err := mgr.Start(stopCh); err != nil {
|
||||||
setupLog.Error(err, "problem running manager")
|
setupLog.Error(err, "problem running manager")
|
||||||
|
|
|
@ -17,16 +17,11 @@ limitations under the License.
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
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/mutating"
|
||||||
"github.com/openkruise/kruise/pkg/webhook/broadcastjob/validating"
|
"github.com/openkruise/kruise/pkg/webhook/broadcastjob/validating"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !gate.ResourceEnabled(&appsv1alpha1.BroadcastJob{}) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
addHandlers(mutating.HandlerMap)
|
addHandlers(mutating.HandlerMap)
|
||||||
addHandlers(validating.HandlerMap)
|
addHandlers(validating.HandlerMap)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,16 +17,11 @@ limitations under the License.
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
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/mutating"
|
||||||
"github.com/openkruise/kruise/pkg/webhook/cloneset/validating"
|
"github.com/openkruise/kruise/pkg/webhook/cloneset/validating"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !gate.ResourceEnabled(&appsv1alpha1.CloneSet{}) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
addHandlers(mutating.HandlerMap)
|
addHandlers(mutating.HandlerMap)
|
||||||
addHandlers(validating.HandlerMap)
|
addHandlers(validating.HandlerMap)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,9 @@ limitations under the License.
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
import (
|
||||||
appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
|
|
||||||
"github.com/openkruise/kruise/pkg/util/gate"
|
|
||||||
"github.com/openkruise/kruise/pkg/webhook/daemonset/mutating"
|
"github.com/openkruise/kruise/pkg/webhook/daemonset/mutating"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !gate.ResourceEnabled(&appsv1alpha1.DaemonSet{}) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
addHandlers(mutating.HandlerMap)
|
addHandlers(mutating.HandlerMap)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,16 +17,11 @@ limitations under the License.
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
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/mutating"
|
||||||
"github.com/openkruise/kruise/pkg/webhook/sidecarset/validating"
|
"github.com/openkruise/kruise/pkg/webhook/sidecarset/validating"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !gate.ResourceEnabled(&appsv1alpha1.SidecarSet{}) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
addHandlers(mutating.HandlerMap)
|
addHandlers(mutating.HandlerMap)
|
||||||
addHandlers(validating.HandlerMap)
|
addHandlers(validating.HandlerMap)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,16 +17,11 @@ limitations under the License.
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
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/mutating"
|
||||||
"github.com/openkruise/kruise/pkg/webhook/statefulset/validating"
|
"github.com/openkruise/kruise/pkg/webhook/statefulset/validating"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !gate.ResourceEnabled(&appsv1alpha1.StatefulSet{}) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
addHandlers(mutating.HandlerMap)
|
addHandlers(mutating.HandlerMap)
|
||||||
addHandlers(validating.HandlerMap)
|
addHandlers(validating.HandlerMap)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,16 +17,11 @@ limitations under the License.
|
||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
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/mutating"
|
||||||
"github.com/openkruise/kruise/pkg/webhook/uniteddeployment/validating"
|
"github.com/openkruise/kruise/pkg/webhook/uniteddeployment/validating"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !gate.ResourceEnabled(&appsv1alpha1.UnitedDeployment{}) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
addHandlers(mutating.HandlerMap)
|
addHandlers(mutating.HandlerMap)
|
||||||
addHandlers(validating.HandlerMap)
|
addHandlers(validating.HandlerMap)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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")
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue