ARO-RP/cmd/aro/rp.go

92 строки
2.3 KiB
Go
Исходник Обычный вид История

2019-10-16 06:29:17 +03:00
package main
2019-12-17 04:16:50 +03:00
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
2019-10-16 06:29:17 +03:00
import (
2019-11-18 06:43:35 +03:00
"context"
"fmt"
2019-10-16 06:29:17 +03:00
"os"
"os/signal"
"syscall"
uuid "github.com/satori/go.uuid"
2019-10-16 06:29:17 +03:00
"github.com/sirupsen/logrus"
"github.com/Azure/ARO-RP/pkg/api"
2020-01-24 14:19:56 +03:00
_ "github.com/Azure/ARO-RP/pkg/api/admin"
_ "github.com/Azure/ARO-RP/pkg/api/v20191231preview"
2019-12-17 04:26:21 +03:00
"github.com/Azure/ARO-RP/pkg/backend"
"github.com/Azure/ARO-RP/pkg/database"
"github.com/Azure/ARO-RP/pkg/env"
"github.com/Azure/ARO-RP/pkg/frontend"
"github.com/Azure/ARO-RP/pkg/metrics/statsd"
"github.com/Azure/ARO-RP/pkg/util/encryption"
2019-10-16 06:29:17 +03:00
)
2019-12-22 20:47:29 +03:00
func rp(ctx context.Context, log *logrus.Entry) error {
for _, key := range []string{
"PULL_SECRET",
} {
if _, found := os.LookupEnv(key); !found {
return fmt.Errorf("environment variable %q unset", key)
}
}
2019-12-22 04:18:17 +03:00
uuid := uuid.NewV4().String()
2019-12-22 20:47:29 +03:00
log.Printf("uuid %s", uuid)
2019-11-18 09:24:26 +03:00
env, err := env.NewEnv(ctx, log)
2019-11-18 09:55:32 +03:00
if err != nil {
return err
}
2020-02-26 03:51:14 +03:00
m, err := statsd.New(ctx, log.WithField("component", "metrics"), env, os.Getenv("MDM_ACCOUNT"), os.Getenv("MDM_NAMESPACE"))
2020-01-09 23:34:15 +03:00
if err != nil {
return err
}
cipher, err := encryption.NewXChaCha20Poly1305(ctx, env)
if err != nil {
return err
}
db, err := database.NewDatabase(ctx, log.WithField("component", "database"), env, m, cipher, uuid)
2019-11-18 07:00:07 +03:00
if err != nil {
return err
2019-11-18 06:43:35 +03:00
}
f, err := frontend.NewFrontend(ctx, log.WithField("component", "frontend"), env, db, api.APIs, m)
if err != nil {
return err
}
b, err := backend.NewBackend(ctx, log.WithField("component", "backend"), env, db, m)
2019-10-16 06:29:17 +03:00
if err != nil {
return err
}
// This part of the code orchestrates shutdown sequence. When sigterm is
// received, it will trigger backend to stop accepting new documents and
// finish old ones. Frontend will stop advertising itself to the loadbalancer.
// When shutdown completes for frontend and backend "/healthz" endpoint
// will go dark and external observer will know that shutdown sequence is finished
sigterm := make(chan os.Signal, 1)
stop := make(chan struct{})
doneF := make(chan struct{})
doneB := make(chan struct{})
signal.Notify(sigterm, syscall.SIGTERM)
2019-10-16 06:29:17 +03:00
log.Print("listening")
go b.Run(ctx, stop, doneB)
go f.Run(ctx, stop, doneF)
2019-10-16 06:29:17 +03:00
<-sigterm
log.Print("received SIGTERM")
close(stop)
<-doneB
<-doneF
2019-10-16 06:29:17 +03:00
2019-12-10 17:58:43 +03:00
return nil
2019-10-16 06:29:17 +03:00
}