polish the code
parent
923a6247a2
commit
839aacf580
4
Makefile
4
Makefile
|
|
@ -826,12 +826,12 @@ out/auto-pause-hook: $(SOURCE_GENERATED) ## Build auto-pause hook addon
|
||||||
|
|
||||||
.PHONY: auto-pause-hook-image
|
.PHONY: auto-pause-hook-image
|
||||||
auto-pause-hook-image: out/auto-pause-hook ## Build docker image for auto-pause hook
|
auto-pause-hook-image: out/auto-pause-hook ## Build docker image for auto-pause hook
|
||||||
docker build -t docker.io/azhao155/auto-pause-hook:1.3 -f deploy/addons/auto-pause/Dockerfile .
|
docker build -t docker.io/azhao155/auto-pause-hook:1.5 -f deploy/addons/auto-pause/Dockerfile .
|
||||||
|
|
||||||
.PHONY: push-auto-pause-hook-image
|
.PHONY: push-auto-pause-hook-image
|
||||||
push-auto-pause-hook-image: auto-pause-hook-image
|
push-auto-pause-hook-image: auto-pause-hook-image
|
||||||
docker login docker.io/azhao155
|
docker login docker.io/azhao155
|
||||||
$(MAKE) push-docker IMAGE=docker.io/azhao155/auto-pause-hook:1.3
|
$(MAKE) push-docker IMAGE=docker.io/azhao155/auto-pause-hook:1.5
|
||||||
|
|
||||||
.PHONY: out/performance-bot
|
.PHONY: out/performance-bot
|
||||||
out/performance-bot:
|
out/performance-bot:
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// generate https certs for the webhook server
|
||||||
func gencerts() (caCert []byte, serverCert []byte, serverKey []byte) {
|
func gencerts() (caCert []byte, serverCert []byte, serverKey []byte) {
|
||||||
var caPEM, serverCertPEM, serverPrivKeyPEM *bytes.Buffer
|
var caPEM, serverCertPEM, serverPrivKeyPEM *bytes.Buffer
|
||||||
// CA config
|
// CA config
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,11 @@ import (
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
webhookName = "env-inject-webhook"
|
||||||
|
webhookConfigName = "env-inject.zyanshu.io"
|
||||||
|
)
|
||||||
|
|
||||||
// get a clientset with in-cluster config.
|
// get a clientset with in-cluster config.
|
||||||
func getClient() *kubernetes.Clientset {
|
func getClient() *kubernetes.Clientset {
|
||||||
config, err := rest.InClusterConfig()
|
config, err := rest.InClusterConfig()
|
||||||
|
|
@ -81,9 +86,9 @@ func configTLS(clientset *kubernetes.Clientset, serverCert []byte, serverKey []b
|
||||||
func selfRegistration(clientset *kubernetes.Clientset, caCert []byte) {
|
func selfRegistration(clientset *kubernetes.Clientset, caCert []byte) {
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
client := clientset.AdmissionregistrationV1().MutatingWebhookConfigurations()
|
client := clientset.AdmissionregistrationV1().MutatingWebhookConfigurations()
|
||||||
_, err := client.Get("env-inject-webhook", metav1.GetOptions{})
|
_, err := client.Get(webhookName, metav1.GetOptions{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if err2 := client.Delete("env-inject-webhook", &metav1.DeleteOptions{}); err2 != nil {
|
if err2 := client.Delete(webhookName, &metav1.DeleteOptions{}); err2 != nil {
|
||||||
glog.Fatal(err2)
|
glog.Fatal(err2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -92,11 +97,11 @@ func selfRegistration(clientset *kubernetes.Clientset, caCert []byte) {
|
||||||
|
|
||||||
webhookConfig := &v1.MutatingWebhookConfiguration{
|
webhookConfig := &v1.MutatingWebhookConfiguration{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "env-inject-webhook",
|
Name: webhookName,
|
||||||
},
|
},
|
||||||
Webhooks: []v1.MutatingWebhook{
|
Webhooks: []v1.MutatingWebhook{
|
||||||
{
|
{
|
||||||
Name: "env-inject.zyanshu.io",
|
Name: webhookConfigName,
|
||||||
Rules: []v1.RuleWithOperations{
|
Rules: []v1.RuleWithOperations{
|
||||||
{
|
{
|
||||||
Operations: []v1.OperationType{v1.Create, v1.Update},
|
Operations: []v1.OperationType{v1.Create, v1.Update},
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"github.com/mattbaird/jsonpatch"
|
"github.com/mattbaird/jsonpatch"
|
||||||
|
|
@ -32,6 +33,7 @@ import (
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||||
|
"k8s.io/minikube/pkg/minikube/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -132,7 +134,7 @@ func patchConfig(pod *corev1.Pod) ([]byte, error) {
|
||||||
|
|
||||||
configEnv := []corev1.EnvVar{
|
configEnv := []corev1.EnvVar{
|
||||||
{Name: "KUBERNETES_SERVICE_HOST", Value: "192.168.49.2"},
|
{Name: "KUBERNETES_SERVICE_HOST", Value: "192.168.49.2"},
|
||||||
{Name: "KUBERNETES_SERVICE_PORT", Value: "32443"}}
|
{Name: "KUBERNETES_SERVICE_PORT", Value: strconv.Itoa(constants.AutoPauseProxyPort)}}
|
||||||
for idx, container := range pod.Spec.Containers {
|
for idx, container := range pod.Spec.Containers {
|
||||||
patch = append(patch, addEnv(container.Env, configEnv, fmt.Sprintf("/spec/containers/%d/env", idx))...)
|
patch = append(patch, addEnv(container.Env, configEnv, fmt.Sprintf("/spec/containers/%d/env", idx))...)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ var Addons = map[string]*Addon{
|
||||||
//GuestPersistentDir
|
//GuestPersistentDir
|
||||||
}, false, "auto-pause", map[string]string{
|
}, false, "auto-pause", map[string]string{
|
||||||
"haproxy": "haproxy:2.3.5",
|
"haproxy": "haproxy:2.3.5",
|
||||||
"AutoPauseHook": "azhao155/auto-pause-hook:1.3",
|
"AutoPauseHook": "azhao155/auto-pause-hook:1.5",
|
||||||
}, map[string]string{
|
}, map[string]string{
|
||||||
"haproxy": "gcr.io",
|
"haproxy": "gcr.io",
|
||||||
"AutoPauseHook": "docker.io",
|
"AutoPauseHook": "docker.io",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue