mirror of https://github.com/k3s-io/k3s
Update dynamiclistener
parent
53d3ab074c
commit
b67b62478b
2
go.mod
2
go.mod
|
@ -96,7 +96,7 @@ require (
|
|||
github.com/opencontainers/runc v1.0.0-rc2.0.20190611121236-6cc515888830
|
||||
github.com/pkg/errors v0.8.1
|
||||
github.com/rakelkar/gonetsh v0.0.0-20190719023240-501daadcadf8 // indirect
|
||||
github.com/rancher/dynamiclistener v0.1.1-0.20191031022009-6224794ef3cb
|
||||
github.com/rancher/dynamiclistener v0.1.1-0.20191108205817-245f86cc340a
|
||||
github.com/rancher/helm-controller v0.2.2
|
||||
github.com/rancher/kine v0.1.2-0.20191107225357-527576e3452f
|
||||
github.com/rancher/remotedialer v0.2.0
|
||||
|
|
2
go.sum
2
go.sum
|
@ -564,6 +564,8 @@ github.com/rancher/cri-tools v1.16.1-k3s.1 h1:iporgQ46noE6dtLzq6fWcIO2qjyPZy2m42
|
|||
github.com/rancher/cri-tools v1.16.1-k3s.1/go.mod h1:TEKhKv2EJIZp+p9jnEy4C63g8CosJzsI4kyKKkHag+8=
|
||||
github.com/rancher/dynamiclistener v0.1.1-0.20191031022009-6224794ef3cb h1:bMoA9UHr1QNTWVrf0fSJCba6YDU1xmt2jmeohpiugKg=
|
||||
github.com/rancher/dynamiclistener v0.1.1-0.20191031022009-6224794ef3cb/go.mod h1:fs/dxyNcB3YT6W9fVz4bDGfhmSQS17QQup6BIcGF++s=
|
||||
github.com/rancher/dynamiclistener v0.1.1-0.20191108205817-245f86cc340a h1:yIQXTC2BjGQ4Bt5Y7QhnxNWbbq8e6koH+pFrJL2VsIs=
|
||||
github.com/rancher/dynamiclistener v0.1.1-0.20191108205817-245f86cc340a/go.mod h1:fs/dxyNcB3YT6W9fVz4bDGfhmSQS17QQup6BIcGF++s=
|
||||
github.com/rancher/flannel v0.11.0-k3s.1 h1:mIwnfWDafjzQgFkZeJ1AkFrrAT3EdBaA1giE0eLJKo8=
|
||||
github.com/rancher/flannel v0.11.0-k3s.1/go.mod h1:Hn4ZV+eq0LhLZP63xZnxdGwXEoRSxs5sxELxu27M3UA=
|
||||
github.com/rancher/helm-controller v0.2.2 h1:MUqisy53/Ay1EYOF2uTCYBbGpgtZLNKKrI01BdxIbQo=
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package dynamiclistener
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
@ -12,7 +11,6 @@ import (
|
|||
func HTTPRedirect(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(
|
||||
func(rw http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("!!!!!", r.URL.String(), r.Header)
|
||||
if r.Header.Get("x-Forwarded-Proto") == "https" ||
|
||||
r.Header.Get("x-Forwarded-Proto") == "wss" ||
|
||||
strings.HasPrefix(r.URL.Path, "/ping") ||
|
||||
|
|
|
@ -9,8 +9,11 @@ import (
|
|||
"github.com/rancher/wrangler-api/pkg/generated/controllers/core"
|
||||
v1controller "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1"
|
||||
"github.com/rancher/wrangler/pkg/start"
|
||||
"github.com/sirupsen/logrus"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/equality"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
type CoreGetter func() *core.Factory
|
||||
|
@ -79,31 +82,56 @@ func (s *storage) Get() (*v1.Secret, error) {
|
|||
return s.storage.Get()
|
||||
}
|
||||
|
||||
func (s *storage) targetSecret() (*v1.Secret, error) {
|
||||
existingSecret, err := s.secrets.Get(s.namespace, s.name, metav1.GetOptions{})
|
||||
if errors.IsNotFound(err) {
|
||||
return &v1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: s.name,
|
||||
Namespace: s.namespace,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
return existingSecret, err
|
||||
}
|
||||
|
||||
func (s *storage) saveInK8s(secret *v1.Secret) (*v1.Secret, error) {
|
||||
if s.secrets == nil {
|
||||
return secret, nil
|
||||
}
|
||||
|
||||
targetSecret, err := s.targetSecret()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if equality.Semantic.DeepEqual(targetSecret.Annotations, secret.Annotations) &&
|
||||
equality.Semantic.DeepEqual(targetSecret.Data, secret.Data) {
|
||||
return secret, nil
|
||||
}
|
||||
|
||||
targetSecret.Annotations = secret.Annotations
|
||||
targetSecret.Type = v1.SecretTypeTLS
|
||||
targetSecret.Data = secret.Data
|
||||
|
||||
if targetSecret.UID == "" {
|
||||
logrus.Infof("Creating new TLS secret for %v", targetSecret.Annotations)
|
||||
return s.secrets.Create(targetSecret)
|
||||
} else {
|
||||
logrus.Infof("Updating TLS secret for %v", targetSecret.Annotations)
|
||||
return s.secrets.Update(targetSecret)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *storage) Update(secret *v1.Secret) (err error) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
if s.secrets != nil {
|
||||
if secret.UID == "" {
|
||||
secret.Name = s.name
|
||||
secret.Namespace = s.namespace
|
||||
secret, err = s.secrets.Create(secret)
|
||||
secret, err = s.saveInK8s(secret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
existingSecret, err := s.storage.Get()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !equality.Semantic.DeepEqual(secret.Data, existingSecret.Data) {
|
||||
secret, err = s.secrets.Update(secret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update underlying storage
|
||||
return s.storage.Update(secret)
|
||||
}
|
||||
|
|
|
@ -726,7 +726,7 @@ github.com/prometheus/procfs/internal/util
|
|||
# github.com/rakelkar/gonetsh v0.0.0-20190719023240-501daadcadf8
|
||||
github.com/rakelkar/gonetsh/netroute
|
||||
github.com/rakelkar/gonetsh/netsh
|
||||
# github.com/rancher/dynamiclistener v0.1.1-0.20191031022009-6224794ef3cb
|
||||
# github.com/rancher/dynamiclistener v0.1.1-0.20191108205817-245f86cc340a
|
||||
github.com/rancher/dynamiclistener
|
||||
github.com/rancher/dynamiclistener/factory
|
||||
github.com/rancher/dynamiclistener/storage/file
|
||||
|
|
Loading…
Reference in New Issue