Fix condition for adding kubernetes endpoints (#3941) (#3951)

* Fix condition for adding kubernetes endpoints

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>

* Fix condition for adding kubernetes endpoints

Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
pull/3963/head v1.21.4-engine0+k3s1
Hussein Galal 2021-09-01 00:03:36 +02:00 committed by GitHub
parent a4c8810e5d
commit 841793de01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 17 deletions

View File

@ -44,23 +44,17 @@ type handler struct {
// This controller will update the version.program/apiaddresses etcd key with a list of
// api addresses endpoints found in the kubernetes service in the default namespace
func (h *handler) sync(key string, endpoint *v1.Endpoints) (*v1.Endpoints, error) {
if endpoint == nil {
return nil, nil
if endpoint != nil &&
endpoint.Namespace == "default" &&
endpoint.Name == "kubernetes" {
w := &bytes.Buffer{}
if err := json.NewEncoder(w).Encode(util.GetAddresses(endpoint)); err != nil {
return nil, err
}
_, err := h.etcdClient.Put(h.ctx, etcd.AddressKey, w.String())
if err != nil {
return nil, err
}
}
if endpoint.Namespace != "default" && endpoint.Name != "kubernetes" {
return nil, nil
}
w := &bytes.Buffer{}
if err := json.NewEncoder(w).Encode(util.GetAddresses(endpoint)); err != nil {
return nil, err
}
_, err := h.etcdClient.Put(h.ctx, etcd.AddressKey, w.String())
if err != nil {
return nil, err
}
return endpoint, nil
}