Skip to content

Commit

Permalink
Consolidate HA model into simple-transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
plorenz committed Sep 6, 2023
1 parent 39d5bf6 commit 806cf14
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 66 deletions.
111 changes: 102 additions & 9 deletions zititest/models/ha/actions/bootstrap.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
/*
(c) Copyright NetFoundry Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package actions

import (
"fmt"
"github.com/openziti/ziti/zititest/zitilab"
"time"

"github.com/openziti/fablab/kernel/lib/actions"
Expand All @@ -23,15 +41,26 @@ func NewBootstrapAction() model.ActionBinder {
func (a *bootstrapAction) bind(m *model.Model) model.Action {
workflow := actions.Workflow()

ctrlCount := len(m.SelectHosts(".ctrl"))

workflow.AddAction(component.Stop(".ctrl"))
workflow.AddAction(host.GroupExec("*", 25, "rm -f logs/*"))
workflow.AddAction(host.GroupExec(".ctrl", 5, "rf -rf ./fablab/ctrldata"))
workflow.AddAction(host.GroupExec("component.ctrl", 5, "rm -rf ./fablab/ctrldata"))

if ctrlCount == 1 {
workflow.AddAction(component.Exec("#ctrl", zitilab.ControllerActionInitStandalone))
}

workflow.AddAction(component.Start(".ctrl"))
workflow.AddAction(semaphore.Sleep(2 * time.Second))
workflow.AddAction(edge.RaftJoin(".ctrl"))
workflow.AddAction(semaphore.Sleep(2 * time.Second))
workflow.AddAction(edge.InitRaftController("#ctrl1"))
workflow.AddAction(semaphore.Sleep(time.Second))

if ctrlCount > 1 {
workflow.AddAction(semaphore.Sleep(2 * time.Second))
workflow.AddAction(edge.RaftJoin(".ctrl"))
workflow.AddAction(semaphore.Sleep(2 * time.Second))
workflow.AddAction(edge.InitRaftController("#ctrl1"))
}

workflow.AddAction(edge.ControllerAvailable("#ctrl1", 30*time.Second))

workflow.AddAction(edge.Login("#ctrl1"))

Expand All @@ -44,10 +73,74 @@ func (a *bootstrapAction) bind(m *model.Model) model.Action {
workflow.AddAction(zitilib_actions.Edge("create", "service-policy", "echo-servers", "Bind", "--service-roles", "@echo", "--identity-roles", "#service"))
workflow.AddAction(zitilib_actions.Edge("create", "service-policy", "echo-client", "Dial", "--service-roles", "@echo", "--identity-roles", "#client"))

workflow.AddAction(zitilib_actions.Edge("create", "edge-router-policy", "echo-servers", "--edge-router-roles", "@router-east", "--identity-roles", "#service"))
workflow.AddAction(zitilib_actions.Edge("create", "edge-router-policy", "echo-clients", "--edge-router-roles", "@router-west", "--identity-roles", "#client"))
workflow.AddAction(zitilib_actions.Edge("create", "edge-router-policy", "echo-servers", "--edge-router-roles", "#host", "--identity-roles", "#service"))
workflow.AddAction(zitilib_actions.Edge("create", "edge-router-policy", "echo-clients", "--edge-router-roles", "#client", "--identity-roles", "#client"))

workflow.AddAction(zitilib_actions.Edge("create", "service-edge-router-policy", "serp-all", "--service-roles", "#all", "--edge-router-roles", "#all"))

workflow.AddAction(zitilib_actions.Edge("create", "config", "files-host", "host.v1", `
{
"address" : "ziti-smoketest-files.s3-us-west-1.amazonaws.com",
"port" : 443,
"protocol" : "tcp"
}`))

workflow.AddAction(zitilib_actions.Edge("create", "config", "iperf-host", "host.v1", `
{
"address" : "localhost",
"port" : 5201,
"protocol" : "tcp"
}`))

for _, encrypted := range []bool{false, true} {
for _, hostType := range []string{"ert", "zet", "ziti-tunnel"} {
suffix := ""
encryptionFlag := "ON"

if !encrypted {
suffix = "-unencrypted"
encryptionFlag = "OFF"
}

filesConfigName := fmt.Sprintf("files-intercept-%s%s", hostType, suffix)
filesConfigDef := fmt.Sprintf(`
{
"addresses": ["files-%s%s.s3-us-west-1.amazonaws.ziti"],
"portRanges" : [ { "low": 443, "high": 443 } ],
"protocols": ["tcp"]
}`, hostType, suffix)

workflow.AddAction(zitilib_actions.Edge("create", "config", filesConfigName, "intercept.v1", filesConfigDef))

iperfConfigName := fmt.Sprintf("iperf-intercept-%s%s", hostType, suffix)
iperfConfigDef := fmt.Sprintf(`
{
"addresses": ["iperf-%s%s.ziti"],
"portRanges" : [ { "low": 5201, "high": 5201 } ],
"protocols": ["tcp"]
}`, hostType, suffix)

workflow.AddAction(zitilib_actions.Edge("create", "config", iperfConfigName, "intercept.v1", iperfConfigDef))

filesServiceName := fmt.Sprintf("%s-files%s", hostType, suffix)
filesConfigs := fmt.Sprintf("files-host,%s", filesConfigName)
workflow.AddAction(zitilib_actions.Edge("create", "service", filesServiceName, "-c", filesConfigs, "-e", encryptionFlag, "-a", hostType))

iperfServiceName := fmt.Sprintf("%s-iperf%s", hostType, suffix)
iperfConfigs := fmt.Sprintf("iperf-host,%s", iperfConfigName)
workflow.AddAction(zitilib_actions.Edge("create", "service", iperfServiceName, "-c", iperfConfigs, "-e", encryptionFlag, "-a", hostType))
}
}

workflow.AddAction(zitilib_actions.Edge("create", "service-policy", "ert-hosts", "Bind", "--service-roles", "#ert", "--identity-roles", "#ert-host"))
workflow.AddAction(zitilib_actions.Edge("create", "service-policy", "zet-hosts", "Bind", "--service-roles", "#zet", "--identity-roles", "#zet-host"))
workflow.AddAction(zitilib_actions.Edge("create", "service-policy", "ziti-tunnel-hosts", "Bind", "--service-roles", "#ziti-tunnel", "--identity-roles", "#ziti-tunnel-host"))
workflow.AddAction(zitilib_actions.Edge("create", "service-policy", "client-tunnelers", "Dial", "--service-roles", "#all", "--identity-roles", "#client"))

workflow.AddAction(zitilib_actions.Edge("create", "edge-router-policy", "client-routers", "--edge-router-roles", "#client", "--identity-roles", "#client"))
workflow.AddAction(zitilib_actions.Edge("create", "edge-router-policy", "host-routers", "--edge-router-roles", "#host", "--identity-roles", "#host"))

workflow.AddAction(zitilib_actions.Edge("create", "service-edge-router-policy", "echo", "--semantic", "AnyOf", "--service-roles", "@echo", "--edge-router-roles", "#all"))
workflow.AddAction(component.Stop(models.ControllerTag))

return workflow
}
13 changes: 9 additions & 4 deletions zititest/models/ha/actions/start.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package actions

import (
"github.com/openziti/ziti/zititest/zitilab/actions/edge"
"time"

"github.com/openziti/fablab/kernel/lib/actions"
Expand All @@ -21,16 +22,20 @@ func NewStartAction(metricbeat MetricbeatConfig, consul ConsulConfig) model.Acti

func (a *startAction) bind(m *model.Model) model.Action {
workflow := actions.Workflow()
workflow.AddAction(component.Start("#ctrl"))
workflow.AddAction(semaphore.Sleep(2 * time.Second))
workflow.AddAction(component.Start(".ctrl"))
workflow.AddAction(edge.ControllerAvailable("#ctrl1", 30*time.Second))
workflow.AddAction(component.StartInParallel(models.EdgeRouterTag, 25))
workflow.AddAction(component.StartInParallel(".iperf", 5))

workflow.AddAction(semaphore.Sleep(2 * time.Second))
workflow.AddAction(zitilib_actions.StartMetricbeat("*", a.Metricbeat.ConfigPath, a.Metricbeat.DataPath, a.Metricbeat.LogPath))
workflow.AddAction(zitilib_actions.StartConsul("*", a.Consul.ServerAddr, a.Consul.ConfigDir, a.Consul.DataPath, a.Consul.LogPath))
workflow.AddAction(semaphore.Sleep(2 * time.Second))
workflow.AddAction(component.Start("#echo-server"))
workflow.AddAction(semaphore.Sleep(2 * time.Second))
workflow.AddAction(component.StartInParallel(".sdk-app", 5))

workflow.AddAction(semaphore.Sleep(5 * time.Second))
workflow.AddAction(zitilib_actions.Edge("list", "edge-routers", "limit none"))
workflow.AddAction(zitilib_actions.Edge("list", "terminators", "limit none"))

return workflow
}
Expand Down
2 changes: 1 addition & 1 deletion zititest/models/ha/configs/router.yml.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{$ssh_username := .Model.MustVariable "credentials.ssh.username"}}
{{$identity := .Component.PublicIdentity}}
{{$identity := .Component.Id}}
{{$router_ip := .Host.PublicIp}}

v: 3
Expand Down
125 changes: 103 additions & 22 deletions zititest/models/ha/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"embed"
"fmt"
"github.com/michaelquigley/pfxlog"
"github.com/openziti/fablab"
"github.com/openziti/fablab/kernel/lib/actions/component"
"github.com/openziti/fablab/kernel/lib/binding"
Expand Down Expand Up @@ -51,12 +52,22 @@ func getConfigData(filePath string) []byte {
return data
}

func getUniqueId() string {
if runId := os.Getenv("GITHUB_RUN_ID"); runId != "" {
return "-" + runId + "." + os.Getenv("GITHUB_RUN_ATTEMPT")
}
return "-" + os.Getenv("USER")
}

var m = &model.Model{
Id: "ha",
Scope: model.Scope{
Defaults: model.Variables{
"environment": "ha-smoketest",
"environment": "ha-smoketest" + getUniqueId(),
"credentials": model.Variables{
"aws": model.Variables{
"managed_key": true,
},
"ssh": model.Variables{
"username": "ubuntu",
},
Expand All @@ -68,6 +79,20 @@ var m = &model.Model{
},
},

Factories: []model.Factory{
model.FactoryFunc(func(m *model.Model) error {
pfxlog.Logger().Infof("environment [%s]", m.MustStringVariable("environment"))
m.AddActivationActions("stop", "bootstrap", "start")
return nil
}),
model.FactoryFunc(func(m *model.Model) error {
return m.ForEachHost("*", 1, func(host *model.Host) error {
host.InstanceType = "t3.micro"
return nil
})
}),
},

Resources: model.Resources{
resources.Configs: resources.SubFolder(configResource, "configs"),
resources.Terraform: test_resources.TerraformResources(),
Expand All @@ -79,7 +104,6 @@ var m = &model.Model{
Site: "us-east-1a",
Hosts: model.Hosts{
"ctrl1": {
InstanceType: "t3.micro",
Components: model.Components{
"ctrl1": {
Scope: model.Scope{Tags: model.Tags{"ctrl"}},
Expand All @@ -88,25 +112,51 @@ var m = &model.Model{
},
},
"ctrl2": {
InstanceType: "t3.micro",
Components: model.Components{
"ctrl2": {
Scope: model.Scope{Tags: model.Tags{"ctrl"}},
Type: &zitilab.ControllerType{},
},
},
},

"router-east": {
InstanceType: "t2.micro",
"router-east-1": {
Scope: model.Scope{Tags: model.Tags{"ert-client"}},
Components: model.Components{
"router-east": {
Scope: model.Scope{Tags: model.Tags{"edge-router", "terminator"}},
"router-east-1": {
Scope: model.Scope{Tags: model.Tags{"edge-router", "terminator", "tunneler", "client"}},
Type: &zitilab.RouterType{},
},
"echo-server": {
Scope: model.Scope{Tags: model.Tags{"sdk-app", "service"}},
Type: &zitilab.EchoServerType{},
"zcat": {
Scope: model.Scope{Tags: model.Tags{"sdk-app", "client"}},
Type: &zitilab.ZCatType{},
},
},
},
"router-east-2": {
Components: model.Components{
"router-east-2": {
Scope: model.Scope{Tags: model.Tags{"edge-router", "initiator"}},
Type: &zitilab.RouterType{},
},
},
},
"ziti-edge-tunnel-client": {
Scope: model.Scope{Tags: model.Tags{"zet-client"}},
Components: model.Components{
"ziti-edge-tunnel-client": {
Scope: model.Scope{Tags: model.Tags{"sdk-app", "client"}},
Type: &zitilab.ZitiEdgeTunnelType{
Version: "v0.21.4",
},
},
},
},
"ziti-tunnel-client": {
Scope: model.Scope{Tags: model.Tags{"ziti-tunnel-client"}},
Components: model.Components{
"ziti-tunnel-client": {
Scope: model.Scope{Tags: model.Tags{"ziti-tunnel", "sdk-app", "client"}},
Type: &zitilab.ZitiTunnelType{},
},
},
},
Expand All @@ -117,7 +167,6 @@ var m = &model.Model{
Site: "us-west-2b",
Hosts: model.Hosts{
"ctrl3": {
InstanceType: "t3.micro",
Components: model.Components{
"ctrl3": {
Scope: model.Scope{Tags: model.Tags{"ctrl"}},
Expand All @@ -127,16 +176,46 @@ var m = &model.Model{
},

"router-west": {
Scope: model.Scope{Tags: model.Tags{}},
InstanceType: "t2.micro",
Components: model.Components{
"router-west": {
Scope: model.Scope{Tags: model.Tags{"edge-router", "terminator"}},
Scope: model.Scope{Tags: model.Tags{"edge-router", "tunneler", "host", "ert-host"}},
Type: &zitilab.RouterType{},
},
"zcat": {
Scope: model.Scope{Tags: model.Tags{"sdk-app"}},
Type: &zitilab.ZCatType{},
"echo-server": {
Scope: model.Scope{Tags: model.Tags{"sdk-app", "service"}},
Type: &zitilab.EchoServerType{},
},
"iperf-server-ert": {
Scope: model.Scope{Tags: model.Tags{"iperf", "service"}},
Type: &zitilab.IPerfServerType{},
},
},
},
"ziti-edge-tunnel-host": {
Components: model.Components{
"ziti-edge-tunnel-host": {
Scope: model.Scope{Tags: model.Tags{"sdk-app", "host", "zet-host"}},
Type: &zitilab.ZitiEdgeTunnelType{
Version: "v0.21.4",
},
},
"iperf-server-zet": {
Scope: model.Scope{Tags: model.Tags{"iperf", "service"}},
Type: &zitilab.IPerfServerType{},
},
},
},
"ziti-tunnel-host": {
Components: model.Components{
"ziti-tunnel-host": {
Scope: model.Scope{Tags: model.Tags{"ziti-tunnel", "sdk-app", "host", "ziti-tunnel-host"}},
Type: &zitilab.ZitiTunnelType{
Mode: zitilab.ZitiTunnelModeHost,
},
},
"iperf-server-zt": {
Scope: model.Scope{Tags: model.Tags{"iperf", "service"}},
Type: &zitilab.IPerfServerType{},
},
},
},
Expand All @@ -163,8 +242,12 @@ var m = &model.Model{

Infrastructure: model.Stages{
aws_ssh_key.Express(),
terraform_0.Express(),
semaphore0.Ready(time.Minute),
&terraform_0.Terraform{
Retries: 3,
ReadyCheck: &semaphore0.ReadyStage{
MaxWait: 90 * time.Second,
},
},
},

Distribution: model.Stages{
Expand Down Expand Up @@ -241,8 +324,6 @@ var m = &model.Model{
}

func main() {
m.AddActivationActions("stop", "bootstrap", "start")

model.AddBootstrapExtension(binding.AwsCredentialsLoader)
model.AddBootstrapExtension(aws_ssh_key.KeyManager)

Expand Down
Loading

0 comments on commit 806cf14

Please sign in to comment.