Skip to content

Add dummy endpoint #1727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions components/buildless-serverless/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ package main
import (
"context"
"github.com/go-logr/zapr"
"os"

"github.com/gorilla/mux"
"github.com/kyma-project/serverless/components/buildless-serverless/internal/config"
"github.com/kyma-project/serverless/components/buildless-serverless/internal/controller/cache"
"github.com/kyma-project/serverless/components/buildless-serverless/internal/controller/orphaned-resources"
"github.com/kyma-project/serverless/components/buildless-serverless/internal/endpoint"
"github.com/kyma-project/serverless/components/buildless-serverless/internal/logging"
"github.com/vrischmann/envconfig"
uberzap "go.uber.org/zap"
uberzapcore "go.uber.org/zap/zapcore"
corev1 "k8s.io/api/core/v1"
"net/http"
"os"
"sigs.k8s.io/controller-runtime/pkg/client"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
Expand Down Expand Up @@ -168,6 +170,8 @@ func main() {
os.Exit(1)
}

startInternalHTTPServer(cfg.DummyPort)

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
Expand All @@ -183,3 +187,17 @@ func loadConfig(prefix string) (serverlessConfig, error) {
}
return cfg, nil
}

func startInternalHTTPServer(port string) {
go func() {
router := mux.NewRouter()
router.HandleFunc("/internal/{namespace}/{name}", endpoint.InternalDummyHandler)

setupLog.Info("Starting internal endpoint server", "address", port)

if err := http.ListenAndServe(port, router); err != nil {
setupLog.Error(err, "Internal HTTP server failed")
os.Exit(1)
}
}()
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type FunctionConfig struct {
FunctionTraceCollectorEndpoint string `yaml:"functionTraceCollectorEndpoint"`
FunctionPublisherProxyAddress string `yaml:"functionPublisherProxyAddress"`
ResourceConfig ResourceConfig `yaml:"resourcesConfiguration"`
DummyPort string `yaml:"cliRenderManifestPort"`
}

func defaultFunctionConfig() FunctionConfig {
Expand All @@ -37,6 +38,7 @@ func defaultFunctionConfig() FunctionConfig {
FunctionReadyRequeueDuration: time.Minute * 5,
PackageRegistryConfigSecretName: "buildless-serverless-package-registry-config",
FunctionPublisherProxyAddress: "http://eventing-publisher-proxy.kyma-system.svc.cluster.local/publish",
DummyPort: ":12137",
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package endpoint

import (
"encoding/json"
"fmt"
"github.com/gorilla/mux"
"go.uber.org/zap"
"net/http"
"time"
)

func InternalDummyHandler(w http.ResponseWriter, r *http.Request) {
log := zap.SugaredLogger{}
vars := mux.Vars(r)
ns := vars["namespace"]
name := vars["name"]

resp := map[string]string{
"namespace": ns,
"name": name,
"time": time.DateTime,
}

log.Info(fmt.Sprintf("------------test-log--------------"))

Check failure on line 24 in components/buildless-serverless/internal/endpoint/handle_internal_endpoint.go

View workflow job for this annotation

GitHub Actions / buildless-serverless-lint

S1039: unnecessary use of fmt.Sprintf (staticcheck)
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(resp)
if err != nil {
log.Error(fmt.Sprintf("failed to encode response: %v", err))
}
}
3 changes: 3 additions & 0 deletions config/buildless-serverless/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ spec:
- containerPort: {{ .Values.containers.manager.metricsPort }}
name: http-metrics
protocol: TCP
- containerPort: 12137
name: internal-http
protocol: TCP
livenessProbe:
httpGet:
path: /healthz
Expand Down
4 changes: 4 additions & 0 deletions config/buildless-serverless/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ spec:
port: 443
protocol: TCP
targetPort: 8443
- name: internal-http
port: 12137
protocol: TCP
targetPort: 12137
selector:
app: serverless
app.kubernetes.io/name: buildless-serverless
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/go-git/go-git/v5 v5.16.0
github.com/go-logr/zapr v1.3.0
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.1
github.com/hashicorp/errwrap v1.1.0
github.com/hashicorp/go-multierror v1.1.1
github.com/libgit2/git2go/v34 v34.0.0
Expand Down
Loading