...

Source file src/github.com/emissary-ingress/emissary/v3/cmd/busyambassador/main.go

Documentation: github.com/emissary-ingress/emissary/v3/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/emissary-ingress/emissary/v3/pkg/busy"
    17  	"github.com/emissary-ingress/emissary/v3/pkg/environment"
    18  
    19  	// commands
    20  	"github.com/emissary-ingress/emissary/v3/cmd/apiext"
    21  	"github.com/emissary-ingress/emissary/v3/cmd/entrypoint"
    22  	"github.com/emissary-ingress/emissary/v3/cmd/kubestatus"
    23  	"github.com/emissary-ingress/emissary/v3/cmd/reproducer"
    24  )
    25  
    26  func noop(_ context.Context) {}
    27  
    28  // Builtin for showing this image's version.
    29  func showVersion(ctx context.Context, version string, args ...string) error {
    30  	fmt.Printf("Version %s\n", version)
    31  
    32  	return nil
    33  }
    34  
    35  func main() {
    36  	// The version number is set at run-time by reading the 'ambassador.version' file.  We do
    37  	// this instead of compiling in a version so that we can promote RC images to GA without
    38  	// recompiling anything.
    39  	//
    40  	// Keep this parsing logic in-sync with VERSION.py.
    41  	//
    42  	// We don't report or log errors here, we just silently fall back to a static "MISSING(XXX)"
    43  	// string.  This is in-part because the code in main() here is running _wicked_ early, and
    44  	// logging setup hasn't happened yet.  Also because any errors will be evident when the
    45  	// version number gets logged and it's this static string.
    46  	version := "MISSING(FILE)"
    47  	if verBytes, err := os.ReadFile("/buildroot/ambassador/python/ambassador.version"); err == nil {
    48  		verLines := strings.Split(string(verBytes), "\n")
    49  		for len(verLines) < 2 {
    50  			verLines = append(verLines, "MISSING(VAL)")
    51  		}
    52  		version = verLines[0]
    53  	}
    54  
    55  	busy.Main("busyambassador", "Ambassador", version, map[string]busy.Command{
    56  		"kubestatus": {Setup: environment.EnvironmentSetupEntrypoint, Run: kubestatus.Main},
    57  		"entrypoint": {Setup: noop, Run: entrypoint.Main},
    58  		"reproducer": {Setup: noop, Run: reproducer.Main},
    59  		"version":    {Setup: noop, Run: showVersion},
    60  		"apiext":     {Setup: noop, Run: apiext.Main},
    61  	})
    62  }
    63  

View as plain text