Skip to content

Commit

Permalink
2024 07 chained deploy cmds (#4)
Browse files Browse the repository at this point in the history
* Chain deploy commands
* Replace env variables before loading jsonnet
* Readme: IAM mgmt details
  • Loading branch information
kleineshertz authored Jul 27, 2024
1 parent 35070f6 commit 57c8a8a
Show file tree
Hide file tree
Showing 23 changed files with 1,658 additions and 1,252 deletions.
7 changes: 3 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
"mode": "debug",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/pkg/cmd/capideploy/capideploy.go",
"envFile": "${env:HOME}/capideploy_aws.rc",
"envFile": "${env:HOME}/capideploy_aws.env",
"args": [
"delete_networking",
"-p=sample.jsonnet",
"-v"
"check_cassandra_status",
"-p=sample.jsonnet", "-v"
]
},
]
Expand Down
4 changes: 2 additions & 2 deletions 1_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if ! grep -q "$BASTION_IP" ~/.ssh/config; then
echo " User $CAPIDEPLOY_SSH_USER" | tee -a ~/.ssh/config
echo " StrictHostKeyChecking=no" | tee -a ~/.ssh/config
echo " UserKnownHostsFile=/dev/null" | tee -a ~/.ssh/config
echo " IdentityFile $CAPIDEPLOY_SSH_PRIVATE_KEY_PATH" | tee -a ~/.ssh/config
echo " IdentityFile $CAPIDEPLOY_AWS_SSH_ROOT_KEYPAIR_PRIVATE_KEY_OR_PATH" | tee -a ~/.ssh/config
fi

set -x
Expand All @@ -65,7 +65,7 @@ set -x
./capideploy config_services "bastion,rabbitmq,prometheus,daemon*" -p sample.jsonnet -v >> deploy.log
#./capideploy config_services "bastion" -p sample.jsonnet -v >> deploy.log

ssh -o StrictHostKeyChecking=no -i $CAPIDEPLOY_SSH_PRIVATE_KEY_PATH -J $BASTION_IP $CAPIDEPLOY_SSH_USER@10.5.0.11 'nodetool describecluster;nodetool status'
ssh -o StrictHostKeyChecking=no -i $CAPIDEPLOY_AWS_SSH_ROOT_KEYPAIR_PRIVATE_KEY_OR_PATH -J $BASTION_IP $CAPIDEPLOY_SSH_USER@10.5.0.11 'nodetool describecluster;nodetool status'

duration=$SECONDS
echo "$(($duration / 60))m $(($duration % 60))s elapsed."
Expand Down
784 changes: 427 additions & 357 deletions README.md

Large diffs are not rendered by default.

28 changes: 19 additions & 9 deletions pkg/cld/cldaws/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,22 @@ func CreateRouteTableForVpc(ec2Client *ec2.Client, goCtx context.Context, tags m
return *out.RouteTable.RouteTableId, nil
}

func GetRouteTableByName(ec2Client *ec2.Client, goCtx context.Context, lb *l.LogBuilder, routeTableName string) (string, string, error) {
func GetRouteTableByName(ec2Client *ec2.Client, goCtx context.Context, lb *l.LogBuilder, routeTableName string) (string, string, string, error) {
out, err := ec2Client.DescribeRouteTables(goCtx, &ec2.DescribeRouteTablesInput{
Filters: []types.Filter{{Name: aws.String("tag:Name"), Values: []string{routeTableName}}}})
lb.AddObject(fmt.Sprintf("DescribeRouteTable(tag:Name=%s)", routeTableName), out)
if err != nil {
return "", "", fmt.Errorf("cannot find route table %s: %s", routeTableName, err.Error())
return "", "", "", fmt.Errorf("cannot find route table %s: %s", routeTableName, err.Error())
}
if len(out.RouteTables) == 0 {
return "", "", nil
return "", "", "", nil
}
return *out.RouteTables[0].RouteTableId, *out.RouteTables[0].VpcId, nil

var associatedSubnetId string
if len(out.RouteTables[0].Associations) > 0 {
associatedSubnetId = *out.RouteTables[0].Associations[0].SubnetId
}
return *out.RouteTables[0].RouteTableId, *out.RouteTables[0].VpcId, associatedSubnetId, nil
}

func DeleteRouteTable(ec2Client *ec2.Client, goCtx context.Context, lb *l.LogBuilder, routeTableId string) error {
Expand Down Expand Up @@ -434,21 +439,26 @@ func DetachInternetGatewayFromVpc(ec2Client *ec2.Client, goCtx context.Context,
return nil
}

func GetVpcDefaultRouteTable(ec2Client *ec2.Client, goCtx context.Context, lb *l.LogBuilder, vpcId string) (string, error) {
func GetVpcDefaultRouteTable(ec2Client *ec2.Client, goCtx context.Context, lb *l.LogBuilder, vpcId string) (string, string, error) {
if vpcId == "" {
return "", fmt.Errorf("empty parameter not allowed: vpcId (%s)", vpcId)
return "", "", fmt.Errorf("empty parameter not allowed: vpcId (%s)", vpcId)
}
out, err := ec2Client.DescribeRouteTables(goCtx, &ec2.DescribeRouteTablesInput{
Filters: []types.Filter{
{Name: aws.String("association.main"), Values: []string{"true"}},
{Name: aws.String("vpc-id"), Values: []string{vpcId}}}})
lb.AddObject(fmt.Sprintf("DescribeRouteTables(association.main=true,vpc-id=%s)", vpcId), out)
if err != nil {
return "", fmt.Errorf("cannot obtain default (main) route table for vpc %s: %s", vpcId, err.Error())
return "", "", fmt.Errorf("cannot obtain default (main) route table for vpc %s: %s", vpcId, err.Error())
}
if len(out.RouteTables) == 0 {
return "", fmt.Errorf("cannot obtain default (main) route table for vpc %s: no route tables returned", vpcId)
return "", "", fmt.Errorf("cannot obtain default (main) route table for vpc %s: no route tables returned", vpcId)
}

var associatedSubnetId string
if len(out.RouteTables[0].Associations) > 0 && out.RouteTables[0].Associations[0].SubnetId != nil {
associatedSubnetId = *out.RouteTables[0].Associations[0].SubnetId
}

return *out.RouteTables[0].RouteTableId, nil
return *out.RouteTables[0].RouteTableId, associatedSubnetId, nil
}
14 changes: 7 additions & 7 deletions pkg/cld/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const DeploymentOperatorTagName string = "DeploymentOperator"
const DeploymentOperatorTagValue string = "capideploy"

type Resource struct {
DeploymentName string
Svc string
Type string
Id string
Name string
State string
BilledState ResourceBilledState
DeploymentName string `json:"deployment_name"`
Svc string `json:"svc"`
Type string `json:"type"`
Id string `json:"id"`
Name string `json:"name"`
State string `json:"state"`
BilledState ResourceBilledState `json:"billed_state"`
}

func (r *Resource) String() string {
Expand Down
Loading

0 comments on commit 57c8a8a

Please sign in to comment.