Skip to content

Commit

Permalink
Merge pull request #3 from niontive/niontive/aks-poc-rp
Browse files Browse the repository at this point in the history
Add Simple HTTP Server
  • Loading branch information
jonathan34c committed Aug 24, 2023
2 parents 7670c6e + 758cd5d commit 58bd87c
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Dockerfile.aro-poc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ FROM ${REGISTRY}/ubi8/ubi-minimal
RUN microdnf update && microdnf clean all
RUN curl -o /etc/pki/ca-trust/source/anchors/AMEROOT_ameroot.crt http://crl.microsoft.com/pkiinfra/certs/AMEROOT_ameroot.crt && update-ca-trust
COPY ./aro /usr/local/bin/
ENTRYPOINT ["aro", "poc"]
EXPOSE 2222/tcp 8080/tcp 8443/tcp 8444/tcp 8445/tcp
ENTRYPOINT ["aro", "poc", "8080"]
EXPOSE 8080/tcp
USER 1000
9 changes: 5 additions & 4 deletions cmd/aro/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main
// Licensed under the Apache License 2.0.

import (
"context"
"flag"
"fmt"
"math/rand"
Expand All @@ -30,7 +31,7 @@ func usage() {
fmt.Fprintf(flag.CommandLine.Output(), " %s rp\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s operator {master,worker}\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s update-versions\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s poc\n", os.Args[0])
fmt.Fprintf(flag.CommandLine.Output(), " %s poc port\n", os.Args[0])
flag.PrintDefaults()
}

Expand All @@ -40,7 +41,7 @@ func main() {
flag.Usage = usage
flag.Parse()

// ctx := context.Background()
ctx := context.Background()
// audit := utillog.GetAuditEntry()
log := utillog.GetLogger()

Expand Down Expand Up @@ -80,8 +81,8 @@ func main() {
checkArgs(1)
// err = updateOCPVersions(ctx, log)
case "poc":
checkArgs(1)
err = poc(log)
checkArgs(2)
err = rpPoc(ctx, log)
default:
usage()
os.Exit(2)
Expand Down
33 changes: 30 additions & 3 deletions cmd/aro/poc.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
package main

import "github.com/sirupsen/logrus"
import (
"context"
"flag"
"os"
"os/signal"
"syscall"

"github.com/Azure/ARO-RP/pkg/poc"
"github.com/sirupsen/logrus"
)

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

func poc(log *logrus.Entry) error {
func rpPoc(ctx context.Context, log *logrus.Entry) error {
log.Print("********** ARO-RP on AKS PoC **********")
return nil

ctx, shutdown := context.WithCancel(ctx)
defer shutdown()
go handleSigterm(log, shutdown)

port := flag.Arg(1)
frontEnd := poc.NewFrontend(log, port)

return frontEnd.Run(ctx)
}

func handleSigterm(log *logrus.Entry, shutdown context.CancelFunc) {
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGTERM)
<-signals

log.Print("received SIGTERM. Terminating...")

shutdown()
}
61 changes: 61 additions & 0 deletions pkg/poc/frontend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package poc

import (
"context"
"log"
"net/http"
"time"

"github.com/go-chi/chi/v5"
"github.com/sirupsen/logrus"
)

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

type frontend struct {
logger *logrus.Entry
port string
}

func NewFrontend(logger *logrus.Entry, port string) frontend {
return frontend{
logger: logger,
port: port,
}
}

func (f *frontend) Run(ctx context.Context) error {
router := f.getRouter()
server := &http.Server{
Addr: ":" + f.port,
Handler: router,
ErrorLog: log.New(f.logger.Writer(), "", 0),
}

go func() {
f.logger.Info("Starting http server...")
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
f.logger.Fatalf("Server listen/serve error: %s", err)
}
}()

<-ctx.Done()

f.logger.Info("Stopping http server")
err := server.Shutdown(context.Background())
if err != nil {
f.logger.Errorf("Server shutdown error: %s", err)
}

return err
}

func (f *frontend) getRouter() chi.Router {
r := chi.NewRouter()
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
f.logger.Infof("Received request: %s", time.Now().String())
w.Write([]byte("****** ARO-RP on AKS PoC ******"))
})
return r
}
1 change: 0 additions & 1 deletion poc/pkg/templates/istio-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: {{ .Values.istio.gateway.name }}
namespace: {{ .Values.istio.namespace }}
spec:
selector:
istio: {{ .Values.istio.name }}
Expand Down
1 change: 0 additions & 1 deletion poc/pkg/templates/istio-virtualService.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: {{ .Values.istio.virtualService.name }}
namespace: {{ .Values.istio.namespace }}
spec:
hosts:
- {{ .Values.istio.gateway.host }}
Expand Down
1 change: 0 additions & 1 deletion poc/pkg/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ affinity: {}
#TODO jonachang: need to add a secret in other PR
istio:
name: aks-istio-ingressgateway-external
namespace: aro-rp-poc
gateway:
name: rp-poc-gateway
#TODO jonachang: need to specify the host once we have the domain name
Expand Down

0 comments on commit 58bd87c

Please sign in to comment.