-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from devtron-labs/release-candidate-v0.23.0
chore: Release candidate v0.23.0
- Loading branch information
Showing
3,474 changed files
with
542,007 additions
and
126,246 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/caarlos0/env" | ||
"github.com/devtron-labs/silver-surfer/app/api" | ||
"github.com/devtron-labs/silver-surfer/app/constants" | ||
grpc2 "github.com/devtron-labs/silver-surfer/app/grpc" | ||
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/recovery" | ||
grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus" | ||
"go.uber.org/zap" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/keepalive" | ||
"google.golang.org/grpc/status" | ||
"log" | ||
"net" | ||
"os" | ||
"runtime/debug" | ||
"time" | ||
) | ||
|
||
type App struct { | ||
grpcServer *grpc.Server | ||
StartupConfig *StartupConfig | ||
logger *zap.SugaredLogger | ||
GrpcHandler *api.GrpcHandlerImpl | ||
} | ||
|
||
func NewApp( | ||
logger *zap.SugaredLogger, | ||
GrpcHandler *api.GrpcHandlerImpl, | ||
) *App { | ||
return &App{ | ||
logger: logger, | ||
GrpcHandler: GrpcHandler, | ||
} | ||
} | ||
|
||
type StartupConfig struct { | ||
GrpcPort int `env:"SERVER_GRPC_PORT" envDefault:"8111"` | ||
GrpcMaxRecvMsgSize int `env:"GRPC_MAX_RECEIVE_MSG_SIZE" envDefault:"20"` // In mb | ||
GrpcMaxSendMsgSize int `env:"GRPC_MAX_SEND_MSG_SIZE" envDefault:"4"` // In mb | ||
} | ||
|
||
func (app *App) Start() { | ||
// Parse config | ||
app.StartupConfig = &StartupConfig{} | ||
err := env.Parse(app.StartupConfig) | ||
if err != nil { | ||
app.logger.Errorw("failed to parse configuration") | ||
os.Exit(2) | ||
} | ||
|
||
// Start gRPC server | ||
err = app.initGrpcServer(app.StartupConfig.GrpcPort) | ||
if err != nil { | ||
app.logger.Errorw("error starting grpc server", "err", err) | ||
os.Exit(2) | ||
} | ||
} | ||
|
||
func (app *App) initGrpcServer(port int) error { | ||
app.logger.Infow("gRPC server starting", "port", app.StartupConfig.GrpcPort) | ||
|
||
//listen on the port | ||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) | ||
if err != nil { | ||
log.Fatalf("failed to start grpcServer %v", err) | ||
return err | ||
} | ||
|
||
grpcPanicRecoveryHandler := func(p any) (err error) { | ||
app.logger.Error(constants.PanicLogIdentifier, "recovered from panic", "panic", p, "stack", string(debug.Stack())) | ||
return status.Errorf(codes.Internal, "%s", p) | ||
} | ||
recoveryOption := recovery.WithRecoveryHandler(grpcPanicRecoveryHandler) | ||
opts := []grpc.ServerOption{ | ||
grpc.MaxRecvMsgSize(app.StartupConfig.GrpcMaxRecvMsgSize * 1024 * 1024), // GRPC Request size | ||
grpc.MaxSendMsgSize(app.StartupConfig.GrpcMaxSendMsgSize * 1024 * 1024), // GRPC Response size | ||
grpc.KeepaliveParams(keepalive.ServerParameters{ | ||
MaxConnectionAge: 10 * time.Second, | ||
}), | ||
grpc.ChainStreamInterceptor( | ||
grpcPrometheus.StreamServerInterceptor, | ||
recovery.StreamServerInterceptor(recoveryOption)), // panic interceptor, should be at last | ||
grpc.ChainUnaryInterceptor( | ||
grpcPrometheus.UnaryServerInterceptor, | ||
recovery.UnaryServerInterceptor(recoveryOption)), // panic interceptor, should be at last | ||
} | ||
// create a new gRPC grpcServer | ||
app.grpcServer = grpc.NewServer(opts...) | ||
|
||
// register Silver Surfer service | ||
grpc2.RegisterSilverSurferServiceServer(app.grpcServer, app.GrpcHandler) | ||
grpcPrometheus.EnableHandlingTimeHistogram() | ||
grpcPrometheus.Register(app.grpcServer) | ||
// start listening on address | ||
if err = app.grpcServer.Serve(lis); err != nil { | ||
log.Fatalf("failed to start: %v", err) | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (app *App) Stop() { | ||
|
||
app.logger.Infow("silver-surfer shutdown initiating") | ||
|
||
// Gracefully stop the gRPC server | ||
app.logger.Info("Stopping gRPC server...") | ||
app.grpcServer.GracefulStop() | ||
|
||
app.logger.Infow("housekeeping done. exiting now") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Binary Build | ||
FROM golang:1.21-alpine3.17 AS build-env | ||
RUN echo $GOPATH | ||
RUN apk add --no-cache git gcc musl-dev | ||
RUN apk add --update make | ||
RUN mkdir /silver-surfer | ||
WORKDIR /silver-surfer | ||
ADD . /silver-surfer/ | ||
RUN rm -rf ./bin | ||
RUN mkdir ./bin | ||
RUN GOOS=linux go build -o ./bin/kubedd-mvc ./app | ||
|
||
# Prod Build | ||
FROM alpine:3.17 | ||
RUN apk add --no-cache ca-certificates | ||
RUN apk update | ||
RUN apk add git | ||
COPY --from=build-env /silver-surfer/bin . | ||
ENTRYPOINT ["./kubedd-mvc"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//go:build wireinject | ||
// +build wireinject | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/devtron-labs/common-lib/utils/k8s" | ||
"github.com/devtron-labs/silver-surfer/app/api" | ||
"github.com/devtron-labs/silver-surfer/app/logger" | ||
"github.com/devtron-labs/silver-surfer/app/service" | ||
"github.com/google/wire" | ||
) | ||
|
||
func InitializeApp() (*App, error) { | ||
wire.Build( | ||
NewApp, | ||
logger.NewSugaredLogger, | ||
api.NewGrpcHandlerImpl, | ||
service.NewClusterUpgradeReadServiceImpl, | ||
wire.Bind(new(service.ClusterUpgradeReadService), new(*service.ClusterUpgradeReadServiceImpl)), | ||
k8s.GetRuntimeConfig, | ||
k8s.NewK8sUtil, | ||
wire.Bind(new(k8s.K8sService), new(*k8s.K8sServiceImpl)), | ||
) | ||
return &App{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package adaptors | ||
|
||
import ( | ||
"github.com/devtron-labs/common-lib/utils/k8s" | ||
"github.com/devtron-labs/common-lib/utils/remoteConnection/bean" | ||
"github.com/devtron-labs/silver-surfer/app/grpc" | ||
"github.com/devtron-labs/silver-surfer/pkg" | ||
) | ||
|
||
func ConvertSummaryValidationResultToGrpcObj(req []pkg.SummaryValidationResult) []*grpc.SummaryValidationResult { | ||
resp := make([]*grpc.SummaryValidationResult, 0, len(req)) | ||
for _, item := range req { | ||
svr := &grpc.SummaryValidationResult{ | ||
FileName: item.FileName, | ||
Kind: item.Kind, | ||
APIVersion: item.APIVersion, | ||
ResourceName: item.ResourceName, | ||
ResourceNamespace: item.ResourceNamespace, | ||
Deleted: item.Deleted, | ||
Deprecated: item.Deprecated, | ||
LatestAPIVersion: item.LatestAPIVersion, | ||
IsVersionSupported: int32(item.IsVersionSupported), | ||
ErrorsForOriginal: ConvertSummarySchemaErrorToGrpcObj(item.ErrorsForOriginal), | ||
ErrorsForLatest: ConvertSummarySchemaErrorToGrpcObj(item.ErrorsForLatest), | ||
DeprecationForOriginal: ConvertSummarySchemaErrorToGrpcObj(item.DeprecationForOriginal), | ||
DeprecationForLatest: ConvertSummarySchemaErrorToGrpcObj(item.DeprecationForLatest), | ||
} | ||
resp = append(resp, svr) | ||
} | ||
return resp | ||
} | ||
|
||
func ConvertSummarySchemaErrorToGrpcObj(req []*pkg.SummarySchemaError) []*grpc.SummarySchemaError { | ||
resp := make([]*grpc.SummarySchemaError, 0, len(req)) | ||
for _, item := range req { | ||
if item != nil { | ||
sse := &grpc.SummarySchemaError{ | ||
Path: item.Path, | ||
SchemaField: item.SchemaField, | ||
Reason: item.Reason, | ||
} | ||
resp = append(resp, sse) | ||
} | ||
} | ||
return resp | ||
} | ||
|
||
func ConvertGrpcObjToClusterConfig(req *grpc.ClusterConfig) *k8s.ClusterConfig { | ||
if req != nil { | ||
return &k8s.ClusterConfig{ | ||
ClusterName: req.ClusterName, | ||
Host: req.ApiServerUrl, | ||
BearerToken: req.Token, | ||
InsecureSkipTLSVerify: req.InsecureSkipTLSVerify, | ||
KeyData: req.KeyData, | ||
CertData: req.CertData, | ||
CAData: req.CaData, | ||
ClusterId: int(req.ClusterId), | ||
RemoteConnectionConfig: ConvertGrpcObjToRemoteConnectionConfig(req.RemoteConnectionConfig), | ||
} | ||
} | ||
return &k8s.ClusterConfig{} | ||
} | ||
|
||
func ConvertGrpcObjToRemoteConnectionConfig(req *grpc.RemoteConnectionConfig) *bean.RemoteConnectionConfigBean { | ||
if req != nil { | ||
return &bean.RemoteConnectionConfigBean{ | ||
ConnectionMethod: bean.RemoteConnectionMethod(req.RemoteConnectionMethod), | ||
ProxyConfig: ConvertGrpcObjToProxyConfig(req.ProxyConfig), | ||
SSHTunnelConfig: ConvertGrpcObjToSSHTunnelConfig(req.SSHTunnelConfig), | ||
} | ||
} | ||
return &bean.RemoteConnectionConfigBean{} | ||
} | ||
|
||
func ConvertGrpcObjToProxyConfig(req *grpc.ProxyConfig) *bean.ProxyConfig { | ||
if req != nil { | ||
return &bean.ProxyConfig{ProxyUrl: req.ProxyUrl} | ||
} | ||
return &bean.ProxyConfig{} | ||
} | ||
|
||
func ConvertGrpcObjToSSHTunnelConfig(req *grpc.SSHTunnelConfig) *bean.SSHTunnelConfig { | ||
if req != nil { | ||
return &bean.SSHTunnelConfig{ | ||
SSHServerAddress: req.SSHServerAddress, | ||
SSHUsername: req.SSHUsername, | ||
SSHPassword: req.SSHPassword, | ||
SSHAuthKey: req.SSHAuthKey, | ||
} | ||
} | ||
return &bean.SSHTunnelConfig{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"github.com/devtron-labs/silver-surfer/app/adaptors" | ||
"github.com/devtron-labs/silver-surfer/app/grpc" | ||
"github.com/devtron-labs/silver-surfer/app/service" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type GrpcHandlerImpl struct { | ||
grpc.UnimplementedSilverSurferServiceServer | ||
logger *zap.SugaredLogger | ||
clusterUpgradeReadService service.ClusterUpgradeReadService | ||
} | ||
|
||
func NewGrpcHandlerImpl( | ||
logger *zap.SugaredLogger, | ||
clusterUpgradeReadService service.ClusterUpgradeReadService, | ||
) *GrpcHandlerImpl { | ||
return &GrpcHandlerImpl{ | ||
logger: logger, | ||
clusterUpgradeReadService: clusterUpgradeReadService, | ||
} | ||
} | ||
|
||
func (impl *GrpcHandlerImpl) GetClusterUpgradeSummaryValidationResult(ctx context.Context, request *grpc.ClusterUpgradeRequest) (*grpc.ClusterUpgradeResponse, error) { | ||
impl.logger.Infow("scan cluster resources compatibility for k8s version upgrade request", "clusterId", request.ClusterConfig.ClusterId, "clusterName", request.ClusterConfig.ClusterName, "serverUrl", request.ClusterConfig.ApiServerUrl) | ||
summaryValidationResult, err := impl.clusterUpgradeReadService.GetClusterUpgradeSummaryValidationResult(request.TargetK8SVersion, request.ClusterConfig) | ||
if err != nil { | ||
impl.logger.Errorw("error in getting cluster upgrade summary validation result", "targetK8sVersion", request.TargetK8SVersion, "err", err) | ||
return nil, err | ||
} | ||
svr := adaptors.ConvertSummaryValidationResultToGrpcObj(summaryValidationResult) | ||
return &grpc.ClusterUpgradeResponse{Results: svr}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package constants | ||
|
||
const ( | ||
PanicLogIdentifier = "DEVTRON_PANIC_RECOVER" | ||
OutputJson = "json" | ||
) |
Oops, something went wrong.