Skip to content

Commit

Permalink
Added support for GCE static IP and SSL (#599)
Browse files Browse the repository at this point in the history
* Implemented GCE cloud provider and added CreateOrUpdateStaticIp

* Added set-static-ip to client and SetStaticIp to protobuf

* Added reserve static ip behavior to ingress specs

* Added client side reserve-static-ip and implemented server side

* Fixed fakeK8s UpdateIngress signature on server/app_test.go

* Changed reserve_static_ip order in protobuf

* Added CheckVirtualHostIsMissing
  • Loading branch information
retpolanne authored Jun 4, 2019
1 parent 85c9507 commit 19b8e5d
Show file tree
Hide file tree
Showing 31 changed files with 799 additions and 196 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ gen-grpc-stubs:
@protoc --go_out=plugins=grpc:. ./pkg/protobuf/deploy/*.proto
@protoc --go_out=plugins=grpc:. ./pkg/protobuf/exec/*.proto
@protoc --go_out=plugins=grpc:. ./pkg/protobuf/build/*.proto
@protoc --go_out=plugins=grpc:. ./pkg/protobuf/service/*.proto

helm-lint:
@helm lint helm/chart/teresa
Expand Down
26 changes: 18 additions & 8 deletions pkg/client/cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ The app name must follow this rules:
With multiple virtual hosts
$ teresa create foo --team bar --vhost foo1.teresa.io,foo2.teresa.io
An app with static IP (GCP only)
$ teresa create foo --team bar --reserve-static-ip
An internal app (without external endpoint)
$ teresa create foo --team bar --internal
Expand Down Expand Up @@ -132,6 +135,11 @@ func createApp(cmd *cobra.Command, args []string) {
client.PrintErrorAndExit("Invalid vhost parameter")
}

reserveStaticIp, err := cmd.Flags().GetBool("reserve-static-ip")
if err != nil {
client.PrintErrorAndExit("Invalid reserve-static-ip parameter")
}

internal, err := cmd.Flags().GetBool("internal")
if err != nil {
client.PrintErrorAndExit("Invalid internal parameter")
Expand Down Expand Up @@ -162,14 +170,15 @@ func createApp(cmd *cobra.Command, args []string) {
_, err = cli.Create(
context.Background(),
&appb.CreateRequest{
Name: name,
Team: team,
ProcessType: processType,
VirtualHost: vHost,
Limits: lim,
Autoscale: as,
Internal: internal,
Protocol: protocol,
Name: name,
Team: team,
ProcessType: processType,
VirtualHost: vHost,
Limits: lim,
Autoscale: as,
Internal: internal,
ReserveStaticIp: reserveStaticIp,
Protocol: protocol,
},
)
if err != nil {
Expand Down Expand Up @@ -928,6 +937,7 @@ func init() {
appCreateCmd.Flags().String("max-memory", "512Mi", "when set, allows the pod to burst memory usage up to 'max-memory'")
appCreateCmd.Flags().String("process-type", "", "app process type")
appCreateCmd.Flags().String("vhost", "", "comma separated list of the app's virtual hosts")
appCreateCmd.Flags().Bool("reserve-static-ip", false, "create an app with static ip (GCP only)")
appCreateCmd.Flags().Bool("internal", false, "create an internal app (without external endpoint)")
appCreateCmd.Flags().String("protocol", "", "app protocol: http, http2, grpc, etc.")

Expand Down
52 changes: 52 additions & 0 deletions pkg/client/cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,27 @@ var serviceEnableSSLCmd = &cobra.Command{
$ teresa service enable-ssl --app myapp --cert arn:aws:iam::xxxxx:server-certificate/cert-name
To enable ssl for the app on gcp (ingress only):
$ teresa service enable-ssl --app myapp --cert cert-name
To only support ssl:
$ teresa service enable-ssl --app myapp --cert arn:aws:iam::xxxxx:server-certificate/cert-name --only`,
Run: serviceEnableSSL,
}

var serviceSetStaticIpCmd = &cobra.Command{
Use: "set-static-ip",
Short: "Set static IP for the app (GCP and ingress only)",
Long: `Set static IP for the app (GCP and ingress only)
To set static IP for the app on aws:
$ teresa service set-static-ip --app myapp --address-name myapp-address`,
Run: serviceSetStaticIp,
}

var serviceInfoCmd = &cobra.Command{
Use: "info <name>",
Short: "Show service info",
Expand Down Expand Up @@ -94,6 +109,39 @@ func serviceEnableSSL(cmd *cobra.Command, args []string) {
fmt.Println("SSL enabled with success")
}

func serviceSetStaticIp(cmd *cobra.Command, args []string) {
if len(args) != 0 {
cmd.Usage()
return
}

appName, err := cmd.Flags().GetString("app")
if err != nil || appName == "" {
client.PrintErrorAndExit("Invalid app parameter")
}

addressName, err := cmd.Flags().GetString("address-name")
if err != nil || addressName == "" {
client.PrintErrorAndExit("Invalid address-name parameter")
}

conn, err := connection.New(cfgFile, cfgCluster)
if err != nil {
client.PrintConnectionErrorAndExit(err)
}
defer conn.Close()

cli := svcpb.NewServiceClient(conn)
req := &svcpb.SetStaticIpRequest{
AppName: appName,
AddressName: addressName,
}
if _, err := cli.SetStaticIp(context.Background(), req); err != nil {
client.PrintErrorAndExit(client.GetErrorMsg(err))
}
fmt.Println("Static IP added with success")
}

func serviceInfo(cmd *cobra.Command, args []string) {
if len(args) != 1 {
cmd.Usage()
Expand Down Expand Up @@ -170,10 +218,14 @@ func serviceWhitelistSourceRanges(cmd *cobra.Command, args []string) {
func init() {
RootCmd.AddCommand(serviceCmd)
serviceCmd.AddCommand(serviceEnableSSLCmd)
serviceCmd.AddCommand(serviceSetStaticIpCmd)
serviceCmd.AddCommand(serviceInfoCmd)
serviceCmd.AddCommand(serviceWhitelistSourceRangesCmd)

serviceEnableSSLCmd.Flags().String("app", "", "app name")
serviceEnableSSLCmd.Flags().String("cert", "", "certificate identifier")
serviceEnableSSLCmd.Flags().Bool("only", false, "only use SSL")

serviceSetStaticIpCmd.Flags().String("app", "", "app name")
serviceSetStaticIpCmd.Flags().String("address-name", "", "static IP address name")
}
Loading

0 comments on commit 19b8e5d

Please sign in to comment.