pax_global_header00006660000000000000000000000064143426623110014514gustar00rootroot0000000000000052 comment=17aa2df4755fd9ab68f476039592493a478cdf62 golang-github-sercand-kuberesolver-3.1.1/000077500000000000000000000000001434266231100203705ustar00rootroot00000000000000golang-github-sercand-kuberesolver-3.1.1/.gitignore000066400000000000000000000000271434266231100223570ustar00rootroot00000000000000.idea kuberesolver.iml golang-github-sercand-kuberesolver-3.1.1/LICENSE000066400000000000000000000261231434266231100214010ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2017 Sercan Degirmenci Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.golang-github-sercand-kuberesolver-3.1.1/README.md000066400000000000000000000042331434266231100216510ustar00rootroot00000000000000# kuberesolver A Grpc name resolver by using kubernetes API. It comes with a small ~250 LOC kubernetes client to find service endpoints. Therefore it won't bloat your binaries. ### USAGE ```go // Import the module import "github.com/sercand/kuberesolver/v3" // Register kuberesolver to grpc before calling grpc.Dial kuberesolver.RegisterInCluster() // it is same as resolver.Register(kuberesolver.NewBuilder(nil /*custom kubernetes client*/ , "kubernetes")) // if schema is 'kubernetes' then grpc will use kuberesolver to resolve addresses cc, err := grpc.Dial("kubernetes:///service.namespace:portname", opts...) ``` An url can be one of the following, [grpc naming docs](https://github.com/grpc/grpc/blob/master/doc/naming.md) ``` kubernetes:///service-name:8080 kubernetes:///service-name:portname kubernetes:///service-name.namespace:8080 kubernetes://namespace/service-name:8080 kubernetes://service-name:8080/ kubernetes://service-name.namespace:8080/ ``` ### Using alternative Schema Use `RegisterInClusterWithSchema(schema)` instead of `RegisterInCluster` on start. ### Client Side Load Balancing You need to pass grpc.WithBalancerName option to grpc on dial: ```go grpc.DialContext(ctx, "kubernetes:///service:grpc", grpc.WithBalancerName("round_robin"), grpc.WithInsecure()) ``` This will create subconnections for each available service endpoints. ### How is this different from dialing to `service.namespace:8080` Connecting to a service by dialing to `service.namespace:8080` uses DNS and it returns service stable IP. Therefore, gRPC doesn't know the endpoint IP addresses and it fails to reconnect to target services in case of failure. Kuberesolver uses kubernetes API to get and watch service endpoint IP addresses. Since it provides and updates all available service endpoints, together with a client-side balancer you can achive zero downtime deployments. ### RBAC You need give `GET` and `WATCH` access to the `endpoints` if you are using RBAC in your cluster. ### Using With TLS You need to a certificate with name `service-name.namespace` in order to connect with TLS to your services. golang-github-sercand-kuberesolver-3.1.1/builder.go000066400000000000000000000153111434266231100223460ustar00rootroot00000000000000package kuberesolver import ( "context" "fmt" "io" "net" "strconv" "strings" "sync" "time" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "google.golang.org/grpc/grpclog" "google.golang.org/grpc/resolver" ) const ( kubernetesSchema = "kubernetes" defaultFreq = time.Minute * 30 ) var ( endpointsForTarget = promauto.NewGaugeVec( prometheus.GaugeOpts{ Name: "kuberesolver_endpoints_total", Help: "The number of endpoints for a given target", }, []string{"target"}, ) addressesForTarget = promauto.NewGaugeVec( prometheus.GaugeOpts{ Name: "kuberesolver_addresses_total", Help: "The number of addresses for a given target", }, []string{"target"}, ) ) type targetInfo struct { serviceName string serviceNamespace string port string resolveByPortName bool useFirstPort bool } func (ti targetInfo) String() string { return fmt.Sprintf("kubernetes://%s/%s:%s", ti.serviceNamespace, ti.serviceName, ti.port) } // RegisterInCluster registers the kuberesolver builder to grpc with kubernetes schema func RegisterInCluster() { RegisterInClusterWithSchema(kubernetesSchema) } // RegisterInClusterWithSchema registers the kuberesolver builder to the grpc with custom schema func RegisterInClusterWithSchema(schema string) { resolver.Register(NewBuilder(nil, schema)) } // NewBuilder creates a kubeBuilder which is used by grpc resolver. func NewBuilder(client K8sClient, schema string) resolver.Builder { return &kubeBuilder{ k8sClient: client, schema: schema, } } type kubeBuilder struct { k8sClient K8sClient schema string } func parseResolverTarget(target resolver.Target) (targetInfo, error) { // kubernetes://default/service:port end := target.Endpoint snamespace := target.Authority // kubernetes://service.default:port/ if end == "" { end = target.Authority snamespace = "" } ti := targetInfo{} if end == "" { return targetInfo{}, fmt.Errorf("target(%q) is empty", target) } var name string var port string if strings.LastIndex(end, ":") < 0 { name = end port = "" ti.useFirstPort = true } else { var err error name, port, err = net.SplitHostPort(end) if err != nil { return targetInfo{}, fmt.Errorf("target endpoint='%s' is invalid. grpc target is %#v, err=%v", end, target, err) } } namesplit := strings.SplitN(name, ".", 2) sname := name if len(namesplit) == 2 { sname = namesplit[0] snamespace = namesplit[1] } ti.serviceName = sname ti.serviceNamespace = snamespace ti.port = port if !ti.useFirstPort { if _, err := strconv.Atoi(ti.port); err != nil { ti.resolveByPortName = true } else { ti.resolveByPortName = false } } return ti, nil } // Build creates a new resolver for the given target. // // gRPC dial calls Build synchronously, and fails if the returned error is // not nil. func (b *kubeBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) { if b.k8sClient == nil { if cl, err := NewInClusterK8sClient(); err == nil { b.k8sClient = cl } else { return nil, err } } ti, err := parseResolverTarget(target) if err != nil { return nil, err } if ti.serviceNamespace == "" { ti.serviceNamespace = getCurrentNamespaceOrDefault() } ctx, cancel := context.WithCancel(context.Background()) r := &kResolver{ target: ti, ctx: ctx, cancel: cancel, cc: cc, rn: make(chan struct{}, 1), k8sClient: b.k8sClient, t: time.NewTimer(defaultFreq), freq: defaultFreq, endpoints: endpointsForTarget.WithLabelValues(ti.String()), addresses: addressesForTarget.WithLabelValues(ti.String()), } go until(func() { r.wg.Add(1) err := r.watch() if err != nil && err != io.EOF { grpclog.Errorf("kuberesolver: watching ended with error='%v', will reconnect again", err) } }, time.Second, ctx.Done()) return r, nil } // Scheme returns the scheme supported by this resolver. // Scheme is defined at https://github.com/grpc/grpc/blob/master/doc/naming.md. func (b *kubeBuilder) Scheme() string { return b.schema } type kResolver struct { target targetInfo ctx context.Context cancel context.CancelFunc cc resolver.ClientConn // rn channel is used by ResolveNow() to force an immediate resolution of the target. rn chan struct{} k8sClient K8sClient // wg is used to enforce Close() to return after the watcher() goroutine has finished. wg sync.WaitGroup t *time.Timer freq time.Duration endpoints prometheus.Gauge addresses prometheus.Gauge } // ResolveNow will be called by gRPC to try to resolve the target name again. // It's just a hint, resolver can ignore this if it's not necessary. func (k *kResolver) ResolveNow(resolver.ResolveNowOptions) { select { case k.rn <- struct{}{}: default: } } // Close closes the resolver. func (k *kResolver) Close() { k.cancel() k.wg.Wait() } func (k *kResolver) makeAddresses(e Endpoints) ([]resolver.Address, string) { var newAddrs []resolver.Address for _, subset := range e.Subsets { port := "" if k.target.useFirstPort { port = strconv.Itoa(subset.Ports[0].Port) } else if k.target.resolveByPortName { for _, p := range subset.Ports { if p.Name == k.target.port { port = strconv.Itoa(p.Port) break } } } else { port = k.target.port } if len(port) == 0 { port = strconv.Itoa(subset.Ports[0].Port) } for _, address := range subset.Addresses { newAddrs = append(newAddrs, resolver.Address{ Type: resolver.Backend, Addr: net.JoinHostPort(address.IP, port), ServerName: fmt.Sprintf("%s.%s", k.target.serviceName, k.target.serviceNamespace), Metadata: nil, }) } } return newAddrs, "" } func (k *kResolver) handle(e Endpoints) { result, _ := k.makeAddresses(e) // k.cc.NewServiceConfig(sc) if len(result) > 0 { k.cc.NewAddress(result) } k.endpoints.Set(float64(len(e.Subsets))) k.addresses.Set(float64(len(result))) } func (k *kResolver) resolve() { e, err := getEndpoints(k.k8sClient, k.target.serviceNamespace, k.target.serviceName) if err == nil { k.handle(e) } else { grpclog.Errorf("kuberesolver: lookup endpoints failed: %v", err) } // Next lookup should happen after an interval defined by k.freq. k.t.Reset(k.freq) } func (k *kResolver) watch() error { defer k.wg.Done() // watch endpoints lists existing endpoints at start sw, err := watchEndpoints(k.k8sClient, k.target.serviceNamespace, k.target.serviceName) if err != nil { return err } for { select { case <-k.ctx.Done(): return nil case <-k.t.C: k.resolve() case <-k.rn: k.resolve() case up, hasMore := <-sw.ResultChan(): if hasMore { k.handle(up.Object) } else { return nil } } } } golang-github-sercand-kuberesolver-3.1.1/builder_test.go000066400000000000000000000121571434266231100234120ustar00rootroot00000000000000package kuberesolver import ( "fmt" "log" "strings" "testing" "google.golang.org/grpc/resolver" "google.golang.org/grpc/serviceconfig" ) func newTestBuilder() resolver.Builder { cl := NewInsecureK8sClient("http://127.0.0.1:8001") return NewBuilder(cl, kubernetesSchema) } type fakeConn struct { cmp chan struct{} found []string } func (fc *fakeConn) UpdateState(resolver.State) { } func (fc *fakeConn) ReportError(e error) { log.Println(e) } func (fc *fakeConn) ParseServiceConfig(serviceConfigJSON string) *serviceconfig.ParseResult { return &serviceconfig.ParseResult{ Config: nil, Err: fmt.Errorf("no implementation for ParseServiceConfig"), } } func (fc *fakeConn) NewAddress(addresses []resolver.Address) { for i, a := range addresses { fc.found = append(fc.found, a.Addr) fmt.Printf("%d, address: %s\n", i, a.Addr) fmt.Printf("%d, servername: %s\n", i, a.ServerName) fmt.Printf("%d, type: %+v\n", i, a.Type) } fc.cmp <- struct{}{} } func (*fakeConn) NewServiceConfig(serviceConfig string) { fmt.Printf("serviceConfig: %s\n", serviceConfig) } func TestBuilder(t *testing.T) { bl := newTestBuilder() fc := &fakeConn{ cmp: make(chan struct{}), } rs, err := bl.Build(resolver.Target{Endpoint: "kube-dns.kube-system:53", Scheme: "kubernetes", Authority: ""}, fc, resolver.BuildOptions{}) if err != nil { t.Fatal(err) } <-fc.cmp if len(fc.found) == 0 { t.Fatal("could not found endpoints") } fmt.Printf("ResolveNow \n") rs.ResolveNow(resolver.ResolveNowOptions{}) <-fc.cmp } // copied from grpc package to test parsing endpoints // split2 returns the values from strings.SplitN(s, sep, 2). // If sep is not found, it returns ("", "", false) instead. func split2(s, sep string) (string, string, bool) { spl := strings.SplitN(s, sep, 2) if len(spl) < 2 { return "", "", false } return spl[0], spl[1], true } // ParseTarget splits target into a resolver.Target struct containing scheme, // authority and endpoint. // // If target is not a valid scheme://authority/endpoint, it returns {Endpoint: // target}. func parseTarget(target string) (ret resolver.Target) { var ok bool ret.Scheme, ret.Endpoint, ok = split2(target, "://") if !ok { return resolver.Target{Endpoint: target} } ret.Authority, ret.Endpoint, ok = split2(ret.Endpoint, "/") if !ok { return resolver.Target{Endpoint: target} } return ret } func TestParseResolverTarget(t *testing.T) { for i, test := range []struct { target resolver.Target want targetInfo err bool }{ {resolver.Target{"", "", ""}, targetInfo{"", "", "", false, false}, true}, {resolver.Target{"", "a", ""}, targetInfo{"a", "", "", false, true}, false}, {resolver.Target{"", "", "a"}, targetInfo{"a", "", "", false, true}, false}, {resolver.Target{"", "a", "b"}, targetInfo{"b", "a", "", false, true}, false}, {resolver.Target{"", "a.b", ""}, targetInfo{"a", "b", "", false, true}, false}, {resolver.Target{"", "", "a.b"}, targetInfo{"a", "b", "", false, true}, false}, {resolver.Target{"", "", "a.b:80"}, targetInfo{"a", "b", "80", false, false}, false}, {resolver.Target{"", "", "a.b:port"}, targetInfo{"a", "b", "port", true, false}, false}, {resolver.Target{"", "a", "b:port"}, targetInfo{"b", "a", "port", true, false}, false}, {resolver.Target{"", "b.a:port", ""}, targetInfo{"b", "a", "port", true, false}, false}, {resolver.Target{"", "b.a:80", ""}, targetInfo{"b", "a", "80", false, false}, false}, } { got, err := parseResolverTarget(test.target) if err == nil && test.err { t.Errorf("case %d: want error but got nil", i) continue } if err != nil && !test.err { t.Errorf("case %d: got '%v' error but don't want an error", i, err) continue } if got != test.want { t.Errorf("case %d parseTarget(%q) = %+v, want %+v", i, test.target, got, test.want) } } } func TestParseTargets(t *testing.T) { for i, test := range []struct { target string want targetInfo err bool }{ {"", targetInfo{}, true}, {"kubernetes:///", targetInfo{}, true}, {"kubernetes://a:30", targetInfo{}, true}, {"kubernetes://a/", targetInfo{"a", "", "", false, true}, false}, {"kubernetes:///a", targetInfo{"a", "", "", false, true}, false}, {"kubernetes://a/b", targetInfo{"b", "a", "", false, true}, false}, {"kubernetes://a.b/", targetInfo{"a", "b", "", false, true}, false}, {"kubernetes:///a.b:80", targetInfo{"a", "b", "80", false, false}, false}, {"kubernetes:///a.b:port", targetInfo{"a", "b", "port", true, false}, false}, {"kubernetes:///a:port", targetInfo{"a", "", "port", true, false}, false}, {"kubernetes://x/a:port", targetInfo{"a", "x", "port", true, false}, false}, {"kubernetes://a.x:port/", targetInfo{"a", "x", "port", true, false}, false}, {"kubernetes://a.x:30/", targetInfo{"a", "x", "30", false, false}, false}, } { got, err := parseResolverTarget(parseTarget(test.target)) if err == nil && test.err { t.Errorf("case %d: want error but got nil", i) continue } if err != nil && !test.err { t.Errorf("case %d:got '%v' error but don't want an error", i, err) continue } if got != test.want { t.Errorf("case %d: parseTarget(%q) = %+v, want %+v", i, test.target, got, test.want) } } } golang-github-sercand-kuberesolver-3.1.1/go.mod000066400000000000000000000002611434266231100214750ustar00rootroot00000000000000module github.com/sercand/kuberesolver/v3 go 1.14 require ( github.com/fsnotify/fsnotify v1.5.4 github.com/prometheus/client_golang v1.7.1 google.golang.org/grpc v1.31.0 ) golang-github-sercand-kuberesolver-3.1.1/go.sum000066400000000000000000000341441434266231100215310ustar00rootroot00000000000000cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.7.1 h1:NTGy1Ja9pByO+xAeH/qiWnLrKtr3hJPNjaVUwnjpdpA= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lNawc= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8= github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.31.0 h1:T7P4R73V3SSDPhH7WW7ATbfViLtmamH0DKrP3f9AuDI= google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= golang-github-sercand-kuberesolver-3.1.1/kubernetes.go000066400000000000000000000122361434266231100230720ustar00rootroot00000000000000package kuberesolver import ( "crypto/tls" "crypto/x509" "encoding/json" "fmt" "io/ioutil" "net" "net/http" "net/url" "os" "strings" "sync" "time" "github.com/fsnotify/fsnotify" ) const ( serviceAccountToken = "/var/run/secrets/kubernetes.io/serviceaccount/token" serviceAccountCACert = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" kubernetesNamespaceFile = "/var/run/secrets/kubernetes.io/serviceaccount/namespace" defaultNamespace = "default" ) // K8sClient is minimal kubernetes client interface type K8sClient interface { Do(req *http.Request) (*http.Response, error) GetRequest(url string) (*http.Request, error) Host() string } type k8sClient struct { host string token string tokenLck sync.RWMutex httpClient *http.Client } func (kc *k8sClient) GetRequest(url string) (*http.Request, error) { if !strings.HasPrefix(url, kc.host) { url = fmt.Sprintf("%s/%s", kc.host, url) } req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err } kc.tokenLck.RLock() defer kc.tokenLck.RUnlock() if len(kc.token) > 0 { req.Header.Set("Authorization", "Bearer "+kc.token) } return req, nil } func (kc *k8sClient) Do(req *http.Request) (*http.Response, error) { return kc.httpClient.Do(req) } func (kc *k8sClient) Host() string { return kc.host } func (kc *k8sClient) setToken(token string) { kc.tokenLck.Lock() defer kc.tokenLck.Unlock() kc.token = token } // NewInClusterK8sClient creates K8sClient if it is inside Kubernetes func NewInClusterK8sClient() (K8sClient, error) { host, port := os.Getenv("KUBERNETES_SERVICE_HOST"), os.Getenv("KUBERNETES_SERVICE_PORT") if len(host) == 0 || len(port) == 0 { return nil, fmt.Errorf("unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined") } token, err := ioutil.ReadFile(serviceAccountToken) if err != nil { return nil, err } ca, err := ioutil.ReadFile(serviceAccountCACert) if err != nil { return nil, err } certPool := x509.NewCertPool() certPool.AppendCertsFromPEM(ca) transport := &http.Transport{TLSClientConfig: &tls.Config{ MinVersion: tls.VersionTLS10, RootCAs: certPool, }} httpClient := &http.Client{Transport: transport, Timeout: time.Nanosecond * 0} client := &k8sClient{ host: "https://" + net.JoinHostPort(host, port), token: string(token), httpClient: httpClient, } // Create a new file watcher to listen for new Service Account tokens watcher, err := fsnotify.NewWatcher() if err != nil { return nil, err } go func() { for { select { case event, ok := <-watcher.Events: if !ok { return } // k8s configmaps uses symlinks, we need this workaround. // original configmap file is removed if event.Op == fsnotify.Remove || event.Op == fsnotify.Chmod { // remove watcher since the file is removed watcher.Remove(event.Name) // add a new watcher pointing to the new symlink/file watcher.Add(serviceAccountToken) token, err := ioutil.ReadFile(serviceAccountToken) if err == nil { client.setToken(string(token)) } } if event.Op&fsnotify.Write == fsnotify.Write { token, err := ioutil.ReadFile(serviceAccountToken) if err == nil { client.setToken(string(token)) } } case _, ok := <-watcher.Errors: if !ok { return } } } }() err = watcher.Add(serviceAccountToken) if err != nil { return nil, err } return client, nil } // NewInsecureK8sClient creates an insecure k8s client which is suitable // to connect kubernetes api behind proxy func NewInsecureK8sClient(apiURL string) K8sClient { return &k8sClient{ host: apiURL, httpClient: http.DefaultClient, } } func getEndpoints(client K8sClient, namespace, targetName string) (Endpoints, error) { u, err := url.Parse(fmt.Sprintf("%s/api/v1/namespaces/%s/endpoints/%s", client.Host(), namespace, targetName)) if err != nil { return Endpoints{}, err } req, err := client.GetRequest(u.String()) if err != nil { return Endpoints{}, err } resp, err := client.Do(req) if err != nil { return Endpoints{}, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return Endpoints{}, fmt.Errorf("invalid response code %d for service %s in namespace %s", resp.StatusCode, targetName, namespace) } result := Endpoints{} err = json.NewDecoder(resp.Body).Decode(&result) return result, err } func watchEndpoints(client K8sClient, namespace, targetName string) (watchInterface, error) { u, err := url.Parse(fmt.Sprintf("%s/api/v1/watch/namespaces/%s/endpoints/%s", client.Host(), namespace, targetName)) if err != nil { return nil, err } req, err := client.GetRequest(u.String()) if err != nil { return nil, err } resp, err := client.Do(req) if err != nil { return nil, err } if resp.StatusCode != http.StatusOK { defer resp.Body.Close() return nil, fmt.Errorf("invalid response code %d for service %s in namespace %s", resp.StatusCode, targetName, namespace) } return newStreamWatcher(resp.Body), nil } func getCurrentNamespaceOrDefault() string { ns, err := ioutil.ReadFile(kubernetesNamespaceFile) if err != nil { return defaultNamespace } return string(ns) } golang-github-sercand-kuberesolver-3.1.1/models.go000066400000000000000000000022321434266231100222010ustar00rootroot00000000000000package kuberesolver type EventType string const ( Added EventType = "ADDED" Modified EventType = "MODIFIED" Deleted EventType = "DELETED" Error EventType = "ERROR" ) // Event represents a single event to a watched resource. type Event struct { Type EventType `json:"type"` Object Endpoints `json:"object"` } type Endpoints struct { Kind string `json:"kind"` ApiVersion string `json:"apiVersion"` Metadata Metadata `json:"metadata"` Subsets []Subset `json:"subsets"` } type Metadata struct { Name string `json:"name"` Namespace string `json:"namespace"` ResourceVersion string `json:"resourceVersion"` Labels map[string]string `json:"labels"` } type Subset struct { Addresses []Address `json:"addresses"` Ports []Port `json:"ports"` } type Address struct { IP string `json:"ip"` TargetRef *ObjectReference `json:"targetRef,omitempty"` } type ObjectReference struct { Kind string `json:"kind"` Name string `json:"name"` Namespace string `json:"namespace"` } type Port struct { Name string `json:"name"` Port int `json:"port"` } golang-github-sercand-kuberesolver-3.1.1/stream.go000066400000000000000000000047521434266231100222220ustar00rootroot00000000000000package kuberesolver import ( "encoding/json" "fmt" "io" "sync" "google.golang.org/grpc/grpclog" ) // Interface can be implemented by anything that knows how to watch and report changes. type watchInterface interface { // Stops watching. Will close the channel returned by ResultChan(). Releases // any resources used by the watch. Stop() // Returns a chan which will receive all the events. If an error occurs // or Stop() is called, this channel will be closed, in which case the // watch should be completely cleaned up. ResultChan() <-chan Event } // StreamWatcher turns any stream for which you can write a Decoder interface // into a watch.Interface. type streamWatcher struct { result chan Event r io.ReadCloser decoder *json.Decoder sync.Mutex stopped bool } // NewStreamWatcher creates a StreamWatcher from the given io.ReadClosers. func newStreamWatcher(r io.ReadCloser) watchInterface { sw := &streamWatcher{ r: r, decoder: json.NewDecoder(r), result: make(chan Event), } go sw.receive() return sw } // ResultChan implements Interface. func (sw *streamWatcher) ResultChan() <-chan Event { return sw.result } // Stop implements Interface. func (sw *streamWatcher) Stop() { sw.Lock() defer sw.Unlock() if !sw.stopped { sw.stopped = true sw.r.Close() } } // stopping returns true if Stop() was called previously. func (sw *streamWatcher) stopping() bool { sw.Lock() defer sw.Unlock() return sw.stopped } // receive reads result from the decoder in a loop and sends down the result channel. func (sw *streamWatcher) receive() { defer close(sw.result) defer sw.Stop() for { obj, err := sw.Decode() if err != nil { // Ignore expected error. if sw.stopping() { return } switch err { case io.EOF: // watch closed normally case io.ErrUnexpectedEOF: grpclog.Infof("kuberesolver: Unexpected EOF during watch stream event decoding: %v", err) default: grpclog.Infof("kuberesolver: Unable to decode an event from the watch stream: %v", err) } return } sw.result <- obj } } // Decode blocks until it can return the next object in the writer. Returns an error // if the writer is closed or an object can't be decoded. func (sw *streamWatcher) Decode() (Event, error) { var got Event if err := sw.decoder.Decode(&got); err != nil { return Event{}, err } switch got.Type { case Added, Modified, Deleted, Error: return got, nil default: return Event{}, fmt.Errorf("got invalid watch event type: %v", got.Type) } } golang-github-sercand-kuberesolver-3.1.1/util.go000066400000000000000000000011351434266231100216740ustar00rootroot00000000000000package kuberesolver import ( "runtime/debug" "time" "google.golang.org/grpc/grpclog" ) func until(f func(), period time.Duration, stopCh <-chan struct{}) { select { case <-stopCh: return default: } for { func() { defer handleCrash() f() }() select { case <-stopCh: return case <-time.After(period): } } } // HandleCrash simply catches a crash and logs an error. Meant to be called via defer. func handleCrash() { if r := recover(); r != nil { callers := string(debug.Stack()) grpclog.Errorf("kuberesolver: recovered from panic: %#v (%v)\n%v", r, r, callers) } }