func TestStorageLast(t *testing.T) { storage := Init(driver.NewMemory()) const name = "angry-bird" // setup storage with test releases setup := func() { // release records rls0 := ReleaseTestData{Name: name, Version: 1, Status: rspb.Status_SUPERSEDED}.ToRelease() rls1 := ReleaseTestData{Name: name, Version: 2, Status: rspb.Status_SUPERSEDED}.ToRelease() rls2 := ReleaseTestData{Name: name, Version: 3, Status: rspb.Status_SUPERSEDED}.ToRelease() rls3 := ReleaseTestData{Name: name, Version: 4, Status: rspb.Status_FAILED}.ToRelease() // create the release records in the storage assertErrNil(t.Fatal, storage.Create(rls0), "Storing release 'angry-bird' (v1)") assertErrNil(t.Fatal, storage.Create(rls1), "Storing release 'angry-bird' (v2)") assertErrNil(t.Fatal, storage.Create(rls2), "Storing release 'angry-bird' (v3)") assertErrNil(t.Fatal, storage.Create(rls3), "Storing release 'angry-bird' (v4)") } setup() h, err := storage.Last(name) if err != nil { t.Fatalf("Failed to query for release history (%q): %s\n", name, err) } if h.Version != 4 { t.Errorf("Expected revision 4, got %d", h.Version) } }
func TestStorageUpdate(t *testing.T) { // initialize storage storage := Init(driver.NewMemory()) // create fake release rls := ReleaseTestData{ Name: "angry-beaver", Version: 1, Status: rspb.Status_DEPLOYED, }.ToRelease() assertErrNil(t.Fatal, storage.Create(rls), "StoreRelease") // modify the release rls.Info.Status.Code = rspb.Status_DELETED assertErrNil(t.Fatal, storage.Update(rls), "UpdateRelease") // retrieve the updated release res, err := storage.Get(rls.Name, rls.Version) assertErrNil(t.Fatal, err, "QueryRelease") // verify updated and fetched releases are the same. if !reflect.DeepEqual(rls, res) { t.Fatalf("Expected %q, got %q", rls, res) } }
// Init initializes a new storage backend with the driver d. // If d is nil, the default in-memory driver is used. func Init(d driver.Driver) *Storage { // default driver is in memory if d == nil { d = driver.NewMemory() } return &Storage{Driver: d} }
func start(c *cobra.Command, args []string) { clientset, err := kube.New(nil).ClientSet() if err != nil { fmt.Fprintf(os.Stderr, "Cannot initialize Kubernetes connection: %s", err) } switch store { case storageMemory: env.Releases = storage.Init(driver.NewMemory()) case storageConfigMap: env.Releases = storage.Init(driver.NewConfigMaps(clientset.Core().ConfigMaps(namespace()))) } lstn, err := net.Listen("tcp", grpcAddr) if err != nil { fmt.Fprintf(os.Stderr, "Server died: %s\n", err) os.Exit(1) } fmt.Printf("Tiller is listening on %s\n", grpcAddr) fmt.Printf("Probes server is listening on %s\n", probeAddr) fmt.Printf("Storage driver is %s\n", env.Releases.Name()) if enableTracing { startTracing(traceAddr) } srvErrCh := make(chan error) probeErrCh := make(chan error) go func() { svc := tiller.NewReleaseServer(env, clientset) services.RegisterReleaseServiceServer(rootServer, svc) if err := rootServer.Serve(lstn); err != nil { srvErrCh <- err } }() go func() { mux := newProbesMux() if err := http.ListenAndServe(probeAddr, mux); err != nil { probeErrCh <- err } }() select { case err := <-srvErrCh: fmt.Fprintf(os.Stderr, "Server died: %s\n", err) os.Exit(1) case err := <-probeErrCh: fmt.Fprintf(os.Stderr, "Probes server died: %s\n", err) } }
// New returns an environment initialized with the defaults. func New() *Environment { e := engine.New() var ey EngineYard = map[string]Engine{ // Currently, the only template engine we support is the GoTpl one. But // we can easily add some here. GoTplEngine: e, } return &Environment{ EngineYard: ey, Releases: storage.Init(driver.NewMemory()), KubeClient: kube.New(nil), } }
func TestStorageList(t *testing.T) { // initialize storage storage := Init(driver.NewMemory()) // setup storage with test releases setup := func() { // release records rls0 := ReleaseTestData{Name: "happy-catdog", Status: rspb.Status_SUPERSEDED}.ToRelease() rls1 := ReleaseTestData{Name: "livid-human", Status: rspb.Status_SUPERSEDED}.ToRelease() rls2 := ReleaseTestData{Name: "relaxed-cat", Status: rspb.Status_SUPERSEDED}.ToRelease() rls3 := ReleaseTestData{Name: "hungry-hippo", Status: rspb.Status_DEPLOYED}.ToRelease() rls4 := ReleaseTestData{Name: "angry-beaver", Status: rspb.Status_DEPLOYED}.ToRelease() rls5 := ReleaseTestData{Name: "opulent-frog", Status: rspb.Status_DELETED}.ToRelease() rls6 := ReleaseTestData{Name: "happy-liger", Status: rspb.Status_DELETED}.ToRelease() // create the release records in the storage assertErrNil(t.Fatal, storage.Create(rls0), "Storing release 'rls0'") assertErrNil(t.Fatal, storage.Create(rls1), "Storing release 'rls1'") assertErrNil(t.Fatal, storage.Create(rls2), "Storing release 'rls2'") assertErrNil(t.Fatal, storage.Create(rls3), "Storing release 'rls3'") assertErrNil(t.Fatal, storage.Create(rls4), "Storing release 'rls4'") assertErrNil(t.Fatal, storage.Create(rls5), "Storing release 'rls5'") assertErrNil(t.Fatal, storage.Create(rls6), "Storing release 'rls6'") } var listTests = []struct { Description string NumExpected int ListFunc func() ([]*rspb.Release, error) }{ {"ListDeleted", 2, storage.ListDeleted}, {"ListDeployed", 2, storage.ListDeployed}, {"ListReleases", 7, storage.ListReleases}, } setup() for _, tt := range listTests { list, err := tt.ListFunc() assertErrNil(t.Fatal, err, tt.Description) // verify the count of releases returned if len(list) != tt.NumExpected { t.Errorf("ListReleases(%s): expected %d, actual %d", tt.Description, tt.NumExpected, len(list)) } } }
func start(c *cobra.Command, args []string) { switch store { case storageMemory: env.Releases = storage.Init(driver.NewMemory()) case storageConfigMap: c, err := env.KubeClient.APIClient() if err != nil { fmt.Fprintf(os.Stderr, "Cannot initialize Kubernetes connection: %s", err) } env.Releases = storage.Init(driver.NewConfigMaps(c.ConfigMaps(environment.TillerNamespace))) } lstn, err := net.Listen("tcp", addr) if err != nil { fmt.Fprintf(os.Stderr, "Server died: %s\n", err) os.Exit(1) } fmt.Printf("Tiller is running on %s\n", addr) fmt.Printf("Tiller probes server is running on %s\n", probe) fmt.Printf("Storage driver is %s\n", env.Releases.Name()) srvErrCh := make(chan error) probeErrCh := make(chan error) go func() { if err := rootServer.Serve(lstn); err != nil { srvErrCh <- err } }() go func() { mux := newProbesMux() if err := http.ListenAndServe(probe, mux); err != nil { probeErrCh <- err } }() select { case err := <-srvErrCh: fmt.Fprintf(os.Stderr, "Server died: %s\n", err) os.Exit(1) case err := <-probeErrCh: fmt.Fprintf(os.Stderr, "Probes server died: %s\n", err) } }
func TestStorageDelete(t *testing.T) { // initialize storage storage := Init(driver.NewMemory()) // create fake release rls := ReleaseTestData{ Name: "angry-beaver", Version: 1, }.ToRelease() assertErrNil(t.Fatal, storage.Create(rls), "StoreRelease") // delete the release res, err := storage.Delete(rls.Name, rls.Version) assertErrNil(t.Fatal, err, "DeleteRelease") // verify updated and fetched releases are the same. if !reflect.DeepEqual(rls, res) { t.Fatalf("Expected %q, got %q", rls, res) } }
func TestStorageDeployed(t *testing.T) { storage := Init(driver.NewMemory()) const name = "angry-bird" const vers = int32(4) // setup storage with test releases setup := func() { // release records rls0 := ReleaseTestData{Name: name, Version: 1, Status: rspb.Status_SUPERSEDED}.ToRelease() rls1 := ReleaseTestData{Name: name, Version: 2, Status: rspb.Status_SUPERSEDED}.ToRelease() rls2 := ReleaseTestData{Name: name, Version: 3, Status: rspb.Status_SUPERSEDED}.ToRelease() rls3 := ReleaseTestData{Name: name, Version: 4, Status: rspb.Status_DEPLOYED}.ToRelease() // create the release records in the storage assertErrNil(t.Fatal, storage.Create(rls0), "Storing release 'angry-bird' (v1)") assertErrNil(t.Fatal, storage.Create(rls1), "Storing release 'angry-bird' (v2)") assertErrNil(t.Fatal, storage.Create(rls2), "Storing release 'angry-bird' (v3)") assertErrNil(t.Fatal, storage.Create(rls3), "Storing release 'angry-bird' (v4)") } setup() rls, err := storage.Deployed(name) if err != nil { t.Fatalf("Failed to query for deployed release: %s\n", err) } switch { case rls == nil: t.Fatalf("Release is nil") case rls.Name != name: t.Fatalf("Expected release name %q, actual %q\n", name, rls.Name) case rls.Version != vers: t.Fatalf("Expected release version %d, actual %d\n", vers, rls.Version) case rls.Info.Status.Code != rspb.Status_DEPLOYED: t.Fatalf("Expected release status 'DEPLOYED', actual %s\n", rls.Info.Status.Code) } }
func mockEnvironment() *environment.Environment { e := environment.New() e.Releases = storage.Init(driver.NewMemory()) e.KubeClient = &environment.PrintingKubeClient{Out: os.Stdout} return e }