Installer: dynamically generate open port requests
App config can mark any of the input (int) fields as having a role.
For such fields installer first will make port reservation request to
Port Allocator, which will dynamically allocate and reserve one of the
available ports for the application. Once application is committed to
config repository, installer makes another request to port allocator
to actually open dynamically reserved port in the ingress service.
Added port reservation logic to Port Allocator. Reservation lasts 30
minutes.
Change-Id: Ic8caa0d04459b1a6e8a351e2ca6964ac15c7253d
diff --git a/core/installer/schema.go b/core/installer/schema.go
index a0acfc3..8ddf73f 100644
--- a/core/installer/schema.go
+++ b/core/installer/schema.go
@@ -2,6 +2,7 @@
import (
"fmt"
+ "strings"
"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
@@ -19,6 +20,7 @@
KindSSHKey = 6
KindNumber = 4
KindArrayString = 8
+ KindPort = 9
)
type Field struct {
@@ -58,6 +60,7 @@
certificateIssuer: string | *""
domain: string
allocatePortAddr: string
+ reservePortAddr: string
}
value: { %s }
@@ -175,6 +178,11 @@
if nameAttr.Err() == nil {
name = nameAttr.Contents()
}
+ role := ""
+ roleAttr := v.Attribute("role")
+ if roleAttr.Err() == nil {
+ role = strings.ToLower(roleAttr.Contents())
+ }
switch v.IncompleteKind() {
case cue.StringKind:
return basicSchema{name, KindString, false}, nil
@@ -183,7 +191,11 @@
case cue.NumberKind:
return basicSchema{name, KindNumber, false}, nil
case cue.IntKind:
- return basicSchema{name, KindInt, false}, nil
+ if role == "port" {
+ return basicSchema{name, KindPort, true}, nil
+ } else {
+ return basicSchema{name, KindInt, false}, nil
+ }
case cue.ListKind:
return basicSchema{name, KindArrayString, false}, nil
case cue.StructKind: