github.com/drycc/workflow-cli@v1.5.3-0.20240322092846-d4ee25983af9/cmd/canary.go (about)

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/drycc/controller-sdk-go/api"
     8  	"github.com/drycc/controller-sdk-go/appsettings"
     9  )
    10  
    11  // CanaryList tells the informations about app's autoscale status
    12  func (d *DryccCmd) CanaryInfo(appID string) error {
    13  	s, appID, err := load(d.ConfigFile, appID)
    14  
    15  	if err != nil {
    16  		return err
    17  	}
    18  
    19  	appSettings, err := appsettings.List(s.Client, appID)
    20  	if d.checkAPICompatibility(s.Client, err) != nil {
    21  		return err
    22  	}
    23  	if len(appSettings.Canaries) > 0 {
    24  		table := d.getDefaultFormatTable([]string{"UUID", "OWNER", "PTYPE", "CREATED", "UPDATED"})
    25  		for _, procType := range appSettings.Canaries {
    26  			table.Append([]string{
    27  				appSettings.UUID,
    28  				appSettings.Owner,
    29  				procType,
    30  				appSettings.Created,
    31  				appSettings.Updated,
    32  			})
    33  		}
    34  		table.Render()
    35  	} else {
    36  		d.Println(fmt.Sprintf("No canaries found in %s app.", appID))
    37  	}
    38  	return nil
    39  }
    40  
    41  // CanaryCreate sets canary options for the app proc type.
    42  func (d *DryccCmd) CanaryCreate(appID string, processType []string) error {
    43  	s, appID, err := load(d.ConfigFile, appID)
    44  
    45  	if err != nil {
    46  		return err
    47  	}
    48  
    49  	d.Printf("Applying canary settings for process type %s on %s... ", strings.Join(processType, ","), appID)
    50  
    51  	quit := progress(d.WOut)
    52  	_, err = appsettings.Set(s.Client, appID, api.AppSettings{Canaries: processType})
    53  
    54  	quit <- true
    55  	<-quit
    56  
    57  	if err != nil {
    58  		return err
    59  	}
    60  
    61  	d.Println("done")
    62  	return nil
    63  }
    64  
    65  // CanaryRemove remove canary for the app proc type.
    66  func (d *DryccCmd) CanaryRemove(appID string, processType []string) error {
    67  	s, appID, err := load(d.ConfigFile, appID)
    68  
    69  	if err != nil {
    70  		return err
    71  	}
    72  
    73  	d.Printf("Removing canary for process type %s on %s... ", strings.Join(processType, ","), appID)
    74  
    75  	quit := progress(d.WOut)
    76  
    77  	err = appsettings.CanaryRemove(s.Client, appID, api.AppSettings{Canaries: processType})
    78  
    79  	quit <- true
    80  	<-quit
    81  
    82  	if err != nil {
    83  		return err
    84  	}
    85  
    86  	d.Println("done")
    87  	return nil
    88  }
    89  
    90  // CanaryRelease release canary for the app.
    91  func (d *DryccCmd) CanaryRelease(appID string) error {
    92  	s, appID, err := load(d.ConfigFile, appID)
    93  
    94  	if err != nil {
    95  		return err
    96  	}
    97  
    98  	d.Printf("Release canary for %s... ", appID)
    99  
   100  	quit := progress(d.WOut)
   101  
   102  	err = appsettings.CanaryRelease(s.Client, appID)
   103  
   104  	quit <- true
   105  	<-quit
   106  
   107  	if err != nil {
   108  		return err
   109  	}
   110  
   111  	d.Println("done")
   112  	return nil
   113  }
   114  
   115  // CanaryRollback rollback canary for the app.
   116  func (d *DryccCmd) CanaryRollback(appID string) error {
   117  	s, appID, err := load(d.ConfigFile, appID)
   118  
   119  	if err != nil {
   120  		return err
   121  	}
   122  
   123  	d.Printf("Rollback canary for %s... ", appID)
   124  
   125  	quit := progress(d.WOut)
   126  
   127  	err = appsettings.CanaryRollback(s.Client, appID)
   128  
   129  	quit <- true
   130  	<-quit
   131  
   132  	if err != nil {
   133  		return err
   134  	}
   135  
   136  	d.Println("done")
   137  	return nil
   138  }