...

Source file src/github.com/datawire/ambassador/v2/cmd/busyambassador/main.go

Documentation: github.com/datawire/ambassador/v2/cmd/busyambassador

     1  // Ambassador combines the various Golang binaries used in the Ambassador
     2  // container, dispatching on os.Args[0] like BusyBox. Note that the
     3  // capabilities_wrapper binary is _not_ included here. That one has special
     4  // permissions magic applied to it that is not appropriate for these other
     5  // binaries.
     6  package main
     7  
     8  import (
     9  	// stdlib
    10  	"context"
    11  	"fmt"
    12  	"os"
    13  	"strings"
    14  
    15  	// 1st-party libs
    16  	"github.com/datawire/ambassador/v2/pkg/busy"
    17  	"github.com/datawire/ambassador/v2/pkg/environment"
    18  
    19  	// commands
    20  	"github.com/datawire/ambassador/v2/cmd/agent"
    21  	"github.com/datawire/ambassador/v2/cmd/apiext"
    22  	"github.com/datawire/ambassador/v2/cmd/entrypoint"
    23  	"github.com/datawire/ambassador/v2/cmd/kubestatus"
    24  	"github.com/datawire/ambassador/v2/cmd/reproducer"
    25  )
    26  
    27  func noop(_ context.Context) {}
    28  
    29  // Builtin for showing this image's version.
    30  func showVersion(ctx context.Context, version string, args ...string) error {
    31  	fmt.Printf("Version %s\n", version)
    32  
    33  	return nil
    34  }
    35  
    36  func main() {
    37  	// The version number is set at run-time by reading the 'ambassador.version' file.  We do
    38  	// this instead of compiling in a version so that we can promote RC images to GA without
    39  	// recompiling anything.
    40  	//
    41  	// Keep this parsing logic in-sync with VERSION.py.
    42  	//
    43  	// We don't report or log errors here, we just silently fall back to a static "MISSING(XXX)"
    44  	// string.  This is in-part because the code in main() here is running _wicked_ early, and
    45  	// logging setup hasn't happened yet.  Also because any errors will be evident when the
    46  	// version number gets logged and it's this static string.
    47  	version := "MISSING(FILE)"
    48  	if verBytes, err := os.ReadFile("/buildroot/ambassador/python/ambassador.version"); err == nil {
    49  		verLines := strings.Split(string(verBytes), "\n")
    50  		for len(verLines) < 2 {
    51  			verLines = append(verLines, "MISSING(VAL)")
    52  		}
    53  		version = verLines[0]
    54  	}
    55  
    56  	busy.Main("busyambassador", "Ambassador", version, map[string]busy.Command{
    57  		"kubestatus": {Setup: environment.EnvironmentSetupEntrypoint, Run: kubestatus.Main},
    58  		"entrypoint": {Setup: noop, Run: entrypoint.Main},
    59  		"reproducer": {Setup: noop, Run: reproducer.Main},
    60  		"agent":      {Setup: environment.EnvironmentSetupEntrypoint, Run: agent.Main},
    61  		"version":    {Setup: noop, Run: showVersion},
    62  		"apiext":     {Setup: noop, Run: apiext.Main},
    63  	})
    64  }
    65  

View as plain text