Skip to content

Commit

Permalink
update the TestWebhookInject.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jianfei Hu committed Jan 28, 2019
1 parent 36fd45c commit a2a7744
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
4 changes: 4 additions & 0 deletions pilot/cmd/pilot-agent/status/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func TestNewServer(t *testing.T) {
httpProbe: `{"/app-health/hello-world/readyz": {"path": "/hello/sunnyvale", "port": 8080},
"/app-health/business/livez": {"port": 9090}}`,
},
// A valid input without any prober info.
{
httpProbe: `{}`,
},
}
for _, tc := range testCases {
_, err := NewServer(Config{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"image": "example.com/proxy:latest",
"args": [
"--statusPort",
"15020"
"15020",
"--kubeAppProberConfig",
"{\"/app-health/hello/livez\":{\"path\":\"/live\",\"port\":80},\"/app-health/hello/readyz\":{\"path\":\"/ready\",\"port\":3333},\"/app-health/second/livez\":{\"port\":9000}}"
],
"resources": {}
}
Expand Down
39 changes: 20 additions & 19 deletions pilot/pkg/kube/inject/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (

meshconfig "istio.io/api/mesh/v1alpha1"
"istio.io/istio/pilot/cmd"
"istio.io/istio/pilot/cmd/pilot-agent/status"
"istio.io/istio/pilot/pkg/model"
"istio.io/istio/pkg/log"
)
Expand Down Expand Up @@ -436,25 +437,25 @@ func createPatch(pod *corev1.Pod, prevStatus *SidecarInjectionStatus, annotation
patch = append(patch, removeImagePullSecrets(pod.Spec.ImagePullSecrets, prevStatus.ImagePullSecrets, "/spec/imagePullSecrets")...)

if appProbers := extractKubeAppProbers(&pod.Spec); appProbers != nil {
// b, err := json.Marshal(appProbers)
// if err != nil {
// log.Errorf("failed to serialize the app prober config %v", err)
// return nil, fmt.Errorf("failed to serialize app prober config %v", err)
// }
// TODO: here see if the sic is used again and again... might need to make a copy if so...
// We don't have to escape json encoding here when using golang libraries.
// sidecar.Args = append(sidecar.Args,
// []string{fmt.Sprintf("--%v", status.KubeAppProberCmdFlagName), string(b)}...)
// var sidecar *corev1.Container
// for i := range sic.Containers {
// if sic.Containers[i].Name == istioProxyContainerName {
// sidecar = &sic.Containers[i].
// break
// }
// }
// if sidecar == nil {
// return nil, nil
// }
b, err := json.Marshal(appProbers)
if err != nil {
log.Errorf("failed to serialize the app prober config %v", err)
return nil, fmt.Errorf("failed to serialize app prober config %v", err)
}
var sidecar *corev1.Container
for i := range sic.Containers {
if sic.Containers[i].Name == istioProxyContainerName {
sidecar = &sic.Containers[i]
break
}
}
if sidecar != nil {
log.Errorf("Not found sidecar container, skip adding k8s app prober config")
// TODO: here see if the sic is used again and again... might need to make a copy if so...
// We don't have to escape json encoding here when using golang libraries.
sidecar.Args = append(sidecar.Args,
[]string{fmt.Sprintf("--%v", status.KubeAppProberCmdFlagName), string(b)}...)
}
}

patch = append(patch, addContainer(pod.Spec.InitContainers, sic.InitContainers, "/spec/initContainers")...)
Expand Down

0 comments on commit a2a7744

Please sign in to comment.