diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index e635841..af532a4 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -12,7 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -name: Integration Tests +name: Integration Test + +env: + CONFIG_FILE: deploy.toml + IMAGE_NAME: $(echo "ghcr.io/${{ github.repository }}/echo" | tr '[:upper:]' '[:lower:]') + WAIT_TIMEOUT: "5m" on: push: @@ -21,71 +26,70 @@ on: pull_request: jobs: - collatz: - name: Build collatz binary - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - name: Checkout collatz example - with: - repository: ServiceWeaver/weaver - ref: 'v0.15.0' - - uses: actions/setup-go@v4 - with: - go-version: '1.20' - cache: true - - name: Build collatz example - working-directory: ./examples/collatz - run: | - # Disable CGO to ensure the binary is statically linked - CGO_ENABLED=0 \ - go build -o collatz - - uses: actions/upload-artifact@v3 - with: - name: collatz-binary - path: ./examples/collatz/collatz deploy: - name: Deploy and run tests runs-on: ubuntu-latest - permissions: - contents: read - packages: write - needs: collatz steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 - with: - go-version: '1.20' - cache: true - - uses: azure/setup-kubectl@v3 - - uses: medyagh/setup-minikube@master - - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Install weaver-kube - run: | - go install ./cmd/weaver-kube - - uses: actions/download-artifact@v3 - with: - name: collatz-binary - path: ./examples/collatz - - name: Run integration script - working-directory: ./examples/collatz - run: ../../dev/integration.sh - shell: bash - env: - IMAGE_NAME: ghcr.io/${{ github.repository }}/example-collatz - - name: Display deployment logs - if: failure() - working-directory: ./examples/collatz - run: | - kubectl get all && \ - kubectl describe pod -l app_name=collatz && \ - kubectl logs -l app_name=collatz - - uses: actions/upload-artifact@v3 - if: always() - with: - name: collatz-kube-manifests - path: ./examples/collatz/kube_*.yaml + - name: Check out the repository + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + cache: true + + - name: Setup kubectl. + uses: azure/setup-kubectl@v3 + + - name: Setup minikube + uses: medyagh/setup-minikube@master + + - name: Login into Github Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Install weaver-kube + run: cd cmd/weaver-kube; go build . + + - name: Build echo example. + run: cd examples/echo; go build . + + - name: Generate app config file + run: | + CONFIG=$(cat << EOF + [serviceweaver] + binary = "./examples/echo/echo" + + [kube] + image = "${{ env.IMAGE_NAME }}" + listeners.echo = {public = true} + EOF + ) + echo "$CONFIG" > ${{ env.CONFIG_FILE }} + + - name: Build the docker image and push + run: ./cmd/weaver-kube/weaver-kube deploy --runInDevMode ${{ env.CONFIG_FILE }} + + - name: Deploy the application + run: kubectl apply -f ./kube_*.yaml + + - name: Get the name of the echo listener service + run: | + NAME=$(timeout ${{ env.WAIT_TIMEOUT }} /bin/sh -c 'while true; do NAME=$(kubectl get service -l lisName=echo -o jsonpath={.items[].metadata.name}) && echo $NAME && break; sleep 2; done') + echo "SERVICE_NAME=$NAME" >> $GITHUB_ENV + + - name: Call the echo endpoint until it succeeds + run: | + timeout ${{ env.WAIT_TIMEOUT }} /bin/sh -c 'while true; do kubectl run -i --rm --restart=Never --image=busybox:latest test-api --command wget -- -q -O - http://${{ env.SERVICE_NAME }}?s=testme && break; sleep 2; done' + + - name: Display deployment logs + if: failure() + run: | + kubectl get all + kubectl describe pod + kubectl logs -l appName=echo + + \ No newline at end of file diff --git a/dev/integration.sh b/dev/integration.sh deleted file mode 100755 index 8d5799d..0000000 --- a/dev/integration.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Google LLC -# -# 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. - -# Exit on command error -set -e - -# Ensure image name is lowercase -IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]') - -echo "Generate weaver.toml" -cat < ./weaver.toml -[serviceweaver] -binary = "./collatz" -[kube] -image = "$IMAGE_NAME" -listeners.collatz = {public = true} -EOT - -# Ensure the binary is executable -chmod +x ./collatz - -echo "Build the docker image and push" -weaver-kube deploy weaver.toml - -echo "Deploy the application" -kubectl apply -f ./kube_*.yaml - -echo "Wait for deployment to be ready" -kubectl wait --for=condition=Available=True --timeout=90s Deployment \ - -l serviceweaver/app_name=collatz - -# Get the load balancer name -LOAD_BALANCER_NAME=$(kubectl get service \ - -l serviceweaver/app_name=collatz \ - -o=go-template \ - --template='{{- range .items -}}{{- if eq .spec.type "LoadBalancer" -}}{{ .metadata.name }}{{- end -}}{{- end -}}') - -echo "Call the API and check the response" -kubectl run -i --rm --restart=Never --image=busybox:latest test-api \ - --command wget -- -q -O - http://$LOAD_BALANCER_NAME/\?x\=10 diff --git a/examples/echo/README.md b/examples/echo/README.md new file mode 100644 index 0000000..21cbf74 --- /dev/null +++ b/examples/echo/README.md @@ -0,0 +1,24 @@ +# Echo + +This directory contains a Service Weaver web application that echos the request +string back to the caller. + +This application exists primarily to test the correctness of the Kube deployer. + +## How to run? + +To run this application inside a Kubernetes cluster, run `weaver kube deploy`. + +```console +$ weaver kube deploy weaver.toml # Generate YAML file +$ kubectl apply -f # Deploy YAML file +``` + +## How to interact with the application? + +Get the IP address of the listener service on your kubernetes cluster. Then run: + +```console +$ curl http://?s=foo +foo +``` \ No newline at end of file diff --git a/examples/echo/echo.go b/examples/echo/echo.go new file mode 100644 index 0000000..f02a5cb --- /dev/null +++ b/examples/echo/echo.go @@ -0,0 +1,45 @@ +// Copyright 2023 Google LLC +// +// 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. + +package main + +import ( + "context" + + "github.com/ServiceWeaver/weaver" + "github.com/ServiceWeaver/weaver/metrics" +) + +// stringLength is a histogram that tracks the length of strings passed to the +// Echo method. +var stringLength = metrics.NewHistogram( + "echo_string_length", + "The length of strings passed to the Echo method", + metrics.NonNegativeBuckets, +) + +// Echoer component. +type Echoer interface { + Echo(context.Context, string) (string, error) +} + +// Implementation of the Echoer component. +type echoer struct { + weaver.Implements[Echoer] +} + +func (e echoer) Echo(ctx context.Context, s string) (string, error) { + stringLength.Put(float64(len(s))) // Update the stringLength metric. + return s, nil +} diff --git a/examples/echo/main.go b/examples/echo/main.go new file mode 100644 index 0000000..6c21dae --- /dev/null +++ b/examples/echo/main.go @@ -0,0 +1,59 @@ +// Copyright 2023 Google LLC +// +// 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. +package main + +import ( + "context" + "flag" + "fmt" + "log" + "net/http" + + "github.com/ServiceWeaver/weaver" +) + +//go:generate weaver generate + +func main() { + // Initialize the Service Weaver application. + flag.Parse() + if err := weaver.Run(context.Background(), serve); err != nil { + log.Fatal(err) + } +} + +type server struct { + weaver.Implements[weaver.Main] + echoer weaver.Ref[Echoer] + lis weaver.Listener `weaver:"echo"` +} + +func serve(ctx context.Context, s *server) error { + // Setup the HTTP handler. + var mux http.ServeMux + mux.Handle("/", weaver.InstrumentHandlerFunc("echo", + func(w http.ResponseWriter, r *http.Request) { + input := r.URL.Query().Get("s") + output, err := s.echoer.Get().Echo(r.Context(), input) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + w.Write([]byte(output)) + })) + mux.HandleFunc(weaver.HealthzURL, weaver.HealthzHandler) + + fmt.Printf("echo listener available on %v\n", s.lis) + return http.Serve(s.lis, &mux) +} diff --git a/examples/echo/weaver_gen.go b/examples/echo/weaver_gen.go new file mode 100644 index 0000000..2a4118b --- /dev/null +++ b/examples/echo/weaver_gen.go @@ -0,0 +1,247 @@ +// Code generated by "weaver generate". DO NOT EDIT. +//go:build !ignoreWeaverGen + +package main + +import ( + "context" + "errors" + "github.com/ServiceWeaver/weaver" + "github.com/ServiceWeaver/weaver/runtime/codegen" + "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/trace" + "reflect" +) + +var _ codegen.LatestVersion = codegen.Version[[0][17]struct{}](` + +ERROR: You generated this file with 'weaver generate' v0.18.0 (codegen +version v0.17.0). The generated code is incompatible with the version of the +github.com/ServiceWeaver/weaver module that you're using. The weaver module +version can be found in your go.mod file or by running the following command. + + go list -m github.com/ServiceWeaver/weaver + +We recommend updating the weaver module and the 'weaver generate' command by +running the following. + + go get github.com/ServiceWeaver/weaver@latest + go install github.com/ServiceWeaver/weaver/cmd/weaver@latest + +Then, re-run 'weaver generate' and re-build your code. If the problem persists, +please file an issue at https://github.com/ServiceWeaver/weaver/issues. + +`) + +func init() { + codegen.Register(codegen.Registration{ + Name: "github.com/ServiceWeaver/weaver-kube/examples/echo/Echoer", + Iface: reflect.TypeOf((*Echoer)(nil)).Elem(), + Impl: reflect.TypeOf(echoer{}), + LocalStubFn: func(impl any, caller string, tracer trace.Tracer) any { + return echoer_local_stub{impl: impl.(Echoer), tracer: tracer, echoMetrics: codegen.MethodMetricsFor(codegen.MethodLabels{Caller: caller, Component: "github.com/ServiceWeaver/weaver-kube/examples/echo/Echoer", Method: "Echo", Remote: false})} + }, + ClientStubFn: func(stub codegen.Stub, caller string) any { + return echoer_client_stub{stub: stub, echoMetrics: codegen.MethodMetricsFor(codegen.MethodLabels{Caller: caller, Component: "github.com/ServiceWeaver/weaver-kube/examples/echo/Echoer", Method: "Echo", Remote: true})} + }, + ServerStubFn: func(impl any, addLoad func(uint64, float64)) codegen.Server { + return echoer_server_stub{impl: impl.(Echoer), addLoad: addLoad} + }, + RefData: "", + }) + codegen.Register(codegen.Registration{ + Name: "github.com/ServiceWeaver/weaver/Main", + Iface: reflect.TypeOf((*weaver.Main)(nil)).Elem(), + Impl: reflect.TypeOf(server{}), + Listeners: []string{"echo"}, + LocalStubFn: func(impl any, caller string, tracer trace.Tracer) any { + return main_local_stub{impl: impl.(weaver.Main), tracer: tracer} + }, + ClientStubFn: func(stub codegen.Stub, caller string) any { return main_client_stub{stub: stub} }, + ServerStubFn: func(impl any, addLoad func(uint64, float64)) codegen.Server { + return main_server_stub{impl: impl.(weaver.Main), addLoad: addLoad} + }, + RefData: "⟦2bd5349f:wEaVeReDgE:github.com/ServiceWeaver/weaver/Main→github.com/ServiceWeaver/weaver-kube/examples/echo/Echoer⟧\n⟦914f1096:wEaVeRlIsTeNeRs:github.com/ServiceWeaver/weaver/Main→echo⟧\n", + }) +} + +// weaver.InstanceOf checks. +var _ weaver.InstanceOf[Echoer] = (*echoer)(nil) +var _ weaver.InstanceOf[weaver.Main] = (*server)(nil) + +// weaver.Router checks. +var _ weaver.Unrouted = (*echoer)(nil) +var _ weaver.Unrouted = (*server)(nil) + +// Local stub implementations. + +type echoer_local_stub struct { + impl Echoer + tracer trace.Tracer + echoMetrics *codegen.MethodMetrics +} + +// Check that echoer_local_stub implements the Echoer interface. +var _ Echoer = (*echoer_local_stub)(nil) + +func (s echoer_local_stub) Echo(ctx context.Context, a0 string) (r0 string, err error) { + // Update metrics. + begin := s.echoMetrics.Begin() + defer func() { s.echoMetrics.End(begin, err != nil, 0, 0) }() + span := trace.SpanFromContext(ctx) + if span.SpanContext().IsValid() { + // Create a child span for this method. + ctx, span = s.tracer.Start(ctx, "main.Echoer.Echo", trace.WithSpanKind(trace.SpanKindInternal)) + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) + } + span.End() + }() + } + + return s.impl.Echo(ctx, a0) +} + +type main_local_stub struct { + impl weaver.Main + tracer trace.Tracer +} + +// Check that main_local_stub implements the weaver.Main interface. +var _ weaver.Main = (*main_local_stub)(nil) + +// Client stub implementations. + +type echoer_client_stub struct { + stub codegen.Stub + echoMetrics *codegen.MethodMetrics +} + +// Check that echoer_client_stub implements the Echoer interface. +var _ Echoer = (*echoer_client_stub)(nil) + +func (s echoer_client_stub) Echo(ctx context.Context, a0 string) (r0 string, err error) { + // Update metrics. + var requestBytes, replyBytes int + begin := s.echoMetrics.Begin() + defer func() { s.echoMetrics.End(begin, err != nil, requestBytes, replyBytes) }() + + span := trace.SpanFromContext(ctx) + if span.SpanContext().IsValid() { + // Create a child span for this method. + ctx, span = s.stub.Tracer().Start(ctx, "main.Echoer.Echo", trace.WithSpanKind(trace.SpanKindClient)) + } + + defer func() { + // Catch and return any panics detected during encoding/decoding/rpc. + if err == nil { + err = codegen.CatchPanics(recover()) + if err != nil { + err = errors.Join(weaver.RemoteCallError, err) + } + } + + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, err.Error()) + } + span.End() + + }() + + // Preallocate a buffer of the right size. + size := 0 + size += (4 + len(a0)) + enc := codegen.NewEncoder() + enc.Reset(size) + + // Encode arguments. + enc.String(a0) + var shardKey uint64 + + // Call the remote method. + requestBytes = len(enc.Data()) + var results []byte + results, err = s.stub.Run(ctx, 0, enc.Data(), shardKey) + replyBytes = len(results) + if err != nil { + err = errors.Join(weaver.RemoteCallError, err) + return + } + + // Decode the results. + dec := codegen.NewDecoder(results) + r0 = dec.String() + err = dec.Error() + return +} + +type main_client_stub struct { + stub codegen.Stub +} + +// Check that main_client_stub implements the weaver.Main interface. +var _ weaver.Main = (*main_client_stub)(nil) + +// Server stub implementations. + +type echoer_server_stub struct { + impl Echoer + addLoad func(key uint64, load float64) +} + +// Check that echoer_server_stub implements the codegen.Server interface. +var _ codegen.Server = (*echoer_server_stub)(nil) + +// GetStubFn implements the codegen.Server interface. +func (s echoer_server_stub) GetStubFn(method string) func(ctx context.Context, args []byte) ([]byte, error) { + switch method { + case "Echo": + return s.echo + default: + return nil + } +} + +func (s echoer_server_stub) echo(ctx context.Context, args []byte) (res []byte, err error) { + // Catch and return any panics detected during encoding/decoding/rpc. + defer func() { + if err == nil { + err = codegen.CatchPanics(recover()) + } + }() + + // Decode arguments. + dec := codegen.NewDecoder(args) + var a0 string + a0 = dec.String() + + // TODO(rgrandl): The deferred function above will recover from panics in the + // user code: fix this. + // Call the local method. + r0, appErr := s.impl.Echo(ctx, a0) + + // Encode the results. + enc := codegen.NewEncoder() + enc.String(r0) + enc.Error(appErr) + return enc.Data(), nil +} + +type main_server_stub struct { + impl weaver.Main + addLoad func(key uint64, load float64) +} + +// Check that main_server_stub implements the codegen.Server interface. +var _ codegen.Server = (*main_server_stub)(nil) + +// GetStubFn implements the codegen.Server interface. +func (s main_server_stub) GetStubFn(method string) func(ctx context.Context, args []byte) ([]byte, error) { + switch method { + default: + return nil + } +} diff --git a/go.mod b/go.mod index 3439053..92dda5a 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,10 @@ go 1.21 require ( github.com/ServiceWeaver/weaver v0.18.0 github.com/google/uuid v1.3.0 + go.opentelemetry.io/otel v1.16.0 go.opentelemetry.io/otel/exporters/jaeger v1.16.0 go.opentelemetry.io/otel/sdk v1.16.0 + go.opentelemetry.io/otel/trace v1.16.0 golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 google.golang.org/protobuf v1.31.0 k8s.io/api v0.27.4 @@ -17,10 +19,12 @@ require ( require ( github.com/BurntSushi/toml v1.3.2 // indirect + github.com/DataDog/hyperloglog v0.0.0-20220804205443-1806d9b66146 // indirect github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/emicklei/go-restful/v3 v3.9.0 // indirect + github.com/felixge/httpsnoop v1.0.3 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect @@ -33,19 +37,22 @@ require ( github.com/google/gnostic v0.5.7-v3refs // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/gofuzz v1.2.0 // indirect + github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect + github.com/lightstep/varopt v1.3.0 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-isatty v0.0.16 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/stoewer/go-strcase v1.2.0 // indirect - go.opentelemetry.io/otel v1.16.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0 // indirect + go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.16.0 // indirect go.opentelemetry.io/otel/metric v1.16.0 // indirect - go.opentelemetry.io/otel/trace v1.16.0 // indirect golang.org/x/mod v0.12.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect diff --git a/go.sum b/go.sum index a8b51b6..b02d9bb 100644 --- a/go.sum +++ b/go.sum @@ -37,6 +37,8 @@ github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/hyperloglog v0.0.0-20220804205443-1806d9b66146 h1:S5WsRc58vIeuhvbz0V0FKs19nTbh5z23DCutLIXJkFA= github.com/DataDog/hyperloglog v0.0.0-20220804205443-1806d9b66146/go.mod h1:hFPkswc42pKhRbeKDKXy05mRi7J1kJ2vMNbvd9erH0M= +github.com/DataDog/mmh3 v0.0.0-20210722141835-012dc69a9e49 h1:EbzDX8HPk5uE2FsJYxD74QmMw0/3CqSKhEr6teh0ncQ= +github.com/DataDog/mmh3 v0.0.0-20210722141835-012dc69a9e49/go.mod h1:SvsjzyJlSg0rKsqYgdcFxeEVflx3ZNAyFfkUHP0TxXg= github.com/ServiceWeaver/weaver v0.18.0 h1:b62r1E9mYnCaPEH+KOT34FsMjSZNLFSlXEnNLTR0pyM= github.com/ServiceWeaver/weaver v0.18.0/go.mod h1:/tJzitb+h8nLeHa4Mk7iIGU5ZV4OGB4C9IvIfD8n/1I= github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df h1:7RFfzj4SSt6nnvCPbCqijJi1nWCd+TqAT3bYCStRC18= @@ -54,6 +56,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/dustin/randbo v0.0.0-20140428231429-7f1b564ca724 h1:1/c0u68+2LRI+XSpduQpV9BnKx1k1P6GTb3MVxCE3w4= +github.com/dustin/randbo v0.0.0-20140428231429-7f1b564ca724/go.mod h1:pTiKQhUCcxt2eQMAnv48oc5nAsmelPm573z44h6PSXc= github.com/emicklei/go-restful/v3 v3.9.0 h1:XwGDlfxEnQZzuopoqxwSEllNcCOM9DhhFyhFIIGKwxE= github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -351,6 +355,7 @@ golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/internal/impl/kube.go b/internal/impl/kube.go index 240ea4a..bede4ee 100644 --- a/internal/impl/kube.go +++ b/internal/impl/kube.go @@ -167,6 +167,7 @@ func (r *replicaSetInfo) deploymentName() string { func (r *replicaSetInfo) buildDeployment() (*v1.Deployment, error) { matchLabels := map[string]string{} podLabels := map[string]string{ + "appName": r.dep.App.Name, "depName": r.deploymentName(), "metrics": r.dep.App.Name, // Needed by Prometheus to scrape the metrics. } @@ -215,39 +216,6 @@ func (r *replicaSetInfo) buildDeployment() (*v1.Deployment, error) { }, nil } -// buildInternalService generates a kubernetes service for a replica set that -// is used for internal communication between weavelets. -// -// TODO(mwhittaker): Double check that this code is unused and delete it. -func (r *replicaSetInfo) buildInternalService() (*corev1.Service, error) { - return &corev1.Service{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "v1", - Kind: "Service", - }, - ObjectMeta: metav1.ObjectMeta{Name: r.deploymentName()}, - Spec: corev1.ServiceSpec{ - Selector: map[string]string{ - "depName": r.deploymentName(), - }, - Ports: []corev1.ServicePort{ - { - Name: "service-port", - Port: servicePort, - Protocol: "TCP", - TargetPort: intstr.IntOrString{IntVal: int32(r.internalPort)}, - }, - { - Name: "metrics-port", - Port: metricsPort, - Protocol: "TCP", - TargetPort: intstr.IntOrString{IntVal: int32(metricsPort)}, - }, - }, - }, - }, nil -} - // buildListenerService generates a kubernetes service for a listener. // // Note that for public listeners, we generate a Load Balancer service because @@ -270,7 +238,12 @@ func (r *replicaSetInfo) buildListenerService(lis *ReplicaSetConfig_Listener) (* APIVersion: "v1", Kind: "Service", }, - ObjectMeta: metav1.ObjectMeta{Name: globalLisName}, + ObjectMeta: metav1.ObjectMeta{ + Name: globalLisName, + Labels: map[string]string{ + "lisName": lis.Name, + }, + }, Spec: corev1.ServiceSpec{ Type: corev1.ServiceType(serviceType), Selector: map[string]string{ @@ -585,20 +558,6 @@ func generateAppDeployment(replicaSets map[string]*replicaSetInfo) ([]byte, erro generated = append(generated, []byte("\n---\n")...) fmt.Fprintf(os.Stderr, "Generated kube autoscaler for replica set %v\n", rs.name) - // Build a service to enable internal communication between the weavelets. - s, err := rs.buildInternalService() - if err != nil { - return nil, fmt.Errorf("unable to create kube service for replica set %s: %w", rs.name, err) - } - content, err = yaml.Marshal(s) - if err != nil { - return nil, err - } - generated = append(generated, []byte(fmt.Sprintf("\n# Service for replica set %s\n", rs.name))...) - generated = append(generated, content...) - generated = append(generated, []byte("\n---\n")...) - fmt.Fprintf(os.Stderr, "Generated kube service for replica set %v\n", rs.name) - // Build a service for each listener. for _, listeners := range rs.components { for _, lis := range listeners.Listeners {