-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hydrator): add commit-server component
Co-authored-by: Alexandre Gaudreault <[email protected]> Co-authored-by: Omer Azmon <[email protected]> Co-authored-by: daengdaengLee <[email protected]> Co-authored-by: Juwon Hwang (Kevin) <[email protected]> Co-authored-by: thisishwan2 <[email protected]> Co-authored-by: mirageoasis <[email protected]> Co-authored-by: Robin Lieb <[email protected]> Co-authored-by: miiiinju1 <[email protected]> Signed-off-by: Michael Crenshaw <[email protected]> go mod tidy Signed-off-by: Michael Crenshaw <[email protected]> one test file for both implementations Signed-off-by: Michael Crenshaw <[email protected]> simplify Signed-off-by: Michael Crenshaw <[email protected]> fix test for linux Signed-off-by: Michael Crenshaw <[email protected]> fix git client mock Signed-off-by: Michael Crenshaw <[email protected]> fix git client mock Signed-off-by: Michael Crenshaw <[email protected]> address comments Signed-off-by: Michael Crenshaw <[email protected]> unit tests Signed-off-by: Michael Crenshaw <[email protected]> lint Signed-off-by: Michael Crenshaw <[email protected]>
- Loading branch information
1 parent
79829ec
commit cb2feec
Showing
43 changed files
with
3,893 additions
and
60 deletions.
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
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
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
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
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,91 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"sync" | ||
"syscall" | ||
|
||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
cmdutil "github.com/argoproj/argo-cd/v2/cmd/util" | ||
"github.com/argoproj/argo-cd/v2/commitserver" | ||
"github.com/argoproj/argo-cd/v2/commitserver/metrics" | ||
"github.com/argoproj/argo-cd/v2/common" | ||
"github.com/argoproj/argo-cd/v2/reposerver/askpass" | ||
"github.com/argoproj/argo-cd/v2/util/cli" | ||
"github.com/argoproj/argo-cd/v2/util/env" | ||
"github.com/argoproj/argo-cd/v2/util/errors" | ||
) | ||
|
||
// NewCommand returns a new instance of an argocd-commit-server command | ||
func NewCommand() *cobra.Command { | ||
var ( | ||
listenHost string | ||
listenPort int | ||
metricsPort int | ||
metricsHost string | ||
) | ||
command := &cobra.Command{ | ||
Use: "argocd-commit-server", | ||
Short: "Run Argo CD Commit Server", | ||
Long: "Argo CD Commit Server is an internal service which commits and pushes hydrated manifests to git. This command runs Commit Server in the foreground.", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
vers := common.GetVersion() | ||
vers.LogStartupInfo( | ||
"Argo CD Commit Server", | ||
map[string]any{ | ||
"port": listenPort, | ||
}, | ||
) | ||
|
||
cli.SetLogFormat(cmdutil.LogFormat) | ||
cli.SetLogLevel(cmdutil.LogLevel) | ||
|
||
metricsServer := metrics.NewMetricsServer() | ||
http.Handle("/metrics", metricsServer.GetHandler()) | ||
go func() { errors.CheckError(http.ListenAndServe(fmt.Sprintf("%s:%d", metricsHost, metricsPort), nil)) }() | ||
|
||
askPassServer := askpass.NewServer(askpass.CommitServerSocketPath) | ||
go func() { errors.CheckError(askPassServer.Run()) }() | ||
|
||
server := commitserver.NewServer(askPassServer, metricsServer) | ||
grpc := server.CreateGRPC() | ||
|
||
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", listenHost, listenPort)) | ||
errors.CheckError(err) | ||
|
||
// Graceful shutdown code adapted from here: https://gist.github.com/embano1/e0bf49d24f1cdd07cffad93097c04f0a | ||
sigCh := make(chan os.Signal, 1) | ||
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM) | ||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
go func() { | ||
s := <-sigCh | ||
log.Printf("got signal %v, attempting graceful shutdown", s) | ||
grpc.GracefulStop() | ||
wg.Done() | ||
}() | ||
|
||
log.Println("starting grpc server") | ||
err = grpc.Serve(listener) | ||
errors.CheckError(err) | ||
wg.Wait() | ||
log.Println("clean shutdown") | ||
|
||
return nil | ||
}, | ||
} | ||
command.Flags().StringVar(&cmdutil.LogFormat, "logformat", env.StringFromEnv("ARGOCD_COMMIT_SERVER_LOGFORMAT", "text"), "Set the logging format. One of: text|json") | ||
command.Flags().StringVar(&cmdutil.LogLevel, "loglevel", env.StringFromEnv("ARGOCD_COMMIT_SERVER_LOGLEVEL", "info"), "Set the logging level. One of: debug|info|warn|error") | ||
command.Flags().StringVar(&listenHost, "address", env.StringFromEnv("ARGOCD_COMMIT_SERVER_LISTEN_ADDRESS", common.DefaultAddressCommitServer), "Listen on given address for incoming connections") | ||
command.Flags().IntVar(&listenPort, "port", common.DefaultPortCommitServer, "Listen on given port for incoming connections") | ||
command.Flags().StringVar(&metricsHost, "metrics-address", env.StringFromEnv("ARGOCD_COMMIT_SERVER_METRICS_LISTEN_ADDRESS", common.DefaultAddressCommitServerMetrics), "Listen on given address for metrics") | ||
command.Flags().IntVar(&metricsPort, "metrics-port", common.DefaultPortCommitServerMetrics, "Start metrics server on given port") | ||
return command | ||
} |
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
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,47 @@ | ||
package apiclient | ||
|
||
import ( | ||
"fmt" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
|
||
"github.com/argoproj/argo-cd/v2/util/io" | ||
) | ||
|
||
// Clientset represents commit server api clients | ||
type Clientset interface { | ||
NewCommitServerClient() (io.Closer, CommitServiceClient, error) | ||
} | ||
|
||
type clientSet struct { | ||
address string | ||
} | ||
|
||
// NewCommitServerClient creates new instance of commit server client | ||
func (c *clientSet) NewCommitServerClient() (io.Closer, CommitServiceClient, error) { | ||
conn, err := NewConnection(c.address) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("failed to open a new connection to commit server: %w", err) | ||
} | ||
return conn, NewCommitServiceClient(conn), nil | ||
} | ||
|
||
// NewConnection creates new connection to commit server | ||
func NewConnection(address string) (*grpc.ClientConn, error) { | ||
var opts []grpc.DialOption | ||
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
|
||
conn, err := grpc.Dial(address, opts...) | ||
if err != nil { | ||
log.Errorf("Unable to connect to commit service with address %s", address) | ||
return nil, err | ||
} | ||
return conn, nil | ||
} | ||
|
||
// NewCommitServerClientset creates new instance of commit server Clientset | ||
func NewCommitServerClientset(address string) Clientset { | ||
return &clientSet{address: address} | ||
} |
Oops, something went wrong.