Skip to content

Commit

Permalink
Merge pull request #4627 from twz123/airgap-pkg-install
Browse files Browse the repository at this point in the history
Install packages before airgapping
  • Loading branch information
twz123 authored Jun 14, 2024
2 parents 56ce037 + cab0882 commit 73b54a5
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions inttest/common/airgap.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ localAddrs:

func (a *Airgap) airgapMachine(ctx context.Context, name, v4CIDRs, v6CIDRs string) error {
const airgapScript = `
apk add --no-cache %s
v4Cidrs='%s'
v6Cidrs='%s'
if [ -n "$v4Cidrs" ]; then
apk add --no-cache iptables
for cidr in $v4Cidrs; do
iptables -A INPUT -s $cidr -j ACCEPT
iptables -A OUTPUT -d $cidr -j ACCEPT
Expand All @@ -168,7 +168,6 @@ func (a *Airgap) airgapMachine(ctx context.Context, name, v4CIDRs, v6CIDRs strin
fi
if [ -n "$v6Cidrs" ]; then
apk add --no-cache ip6tables
for cidr in $v6Cidrs; do
ip6tables -A INPUT -s $cidr -j ACCEPT
ip6tables -A OUTPUT -d $cidr -j ACCEPT
Expand All @@ -183,6 +182,18 @@ func (a *Airgap) airgapMachine(ctx context.Context, name, v4CIDRs, v6CIDRs strin
fi
`

var packages []string
if v4CIDRs != "" {
packages = append(packages, "iptables")
}
if v6CIDRs != "" {
packages = append(packages, "ip6tables")
}

if len(packages) < 1 {
return nil
}

a.Logf("Airgapping %s", name)

ssh, err := a.SSH(ctx, name)
Expand All @@ -192,6 +203,6 @@ func (a *Airgap) airgapMachine(ctx context.Context, name, v4CIDRs, v6CIDRs strin
defer ssh.Disconnect()

return ssh.Exec(ctx, "sh -e -", SSHStreams{
In: strings.NewReader(fmt.Sprintf(airgapScript, v4CIDRs, v6CIDRs)),
In: strings.NewReader(fmt.Sprintf(airgapScript, strings.Join(packages, " "), v4CIDRs, v6CIDRs)),
})
}

0 comments on commit 73b54a5

Please sign in to comment.