Skip to content

Commit

Permalink
Merge pull request #92 from metal-stack/multi-filesystem-support
Browse files Browse the repository at this point in the history
support os-installations with multiple filesystems
  • Loading branch information
mwindower authored May 31, 2021
2 parents 1103f2b + e9b4e0d commit ff41101
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
8 changes: 4 additions & 4 deletions pkg/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"text/template"

"github.com/go-logr/logr"
Expand All @@ -17,7 +18,6 @@ import (
const (
MetalKnowledgeBase = "/etc/metal/install.yaml"
FrrConfig = "/etc/frr/frr.conf"
TmpPath = "/var/tmp"
)

//go:embed *.tpl
Expand All @@ -44,7 +44,7 @@ func ReconcileNetwork(f firewallv1.Firewall, log logr.Logger) (bool, error) {
}
kb.Networks = newNetworks

tmpFile, err := tmpFile("frr.conf")
tmpFile, err := tmpFile(FrrConfig)
if err != nil {
return false, fmt.Errorf("error during network reconcilation %v: %w", tmpFile, err)
}
Expand All @@ -66,8 +66,8 @@ func ReconcileNetwork(f firewallv1.Firewall, log logr.Logger) (bool, error) {
return changed, nil
}

func tmpFile(prefix string) (string, error) {
f, err := ioutil.TempFile(TmpPath, prefix)
func tmpFile(file string) (string, error) {
f, err := ioutil.TempFile(filepath.Dir(file), filepath.Base(file))
if err != nil {
return "", err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/nftables/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"

"github.com/go-logr/logr"
"github.com/hashicorp/go-multierror"
Expand All @@ -14,7 +15,6 @@ import (
mn "github.com/metal-stack/metal-lib/pkg/net"
"github.com/vishvananda/netlink"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
)

Expand Down Expand Up @@ -54,7 +54,7 @@ type forwardingRules struct {
// NewDefaultFirewall creates a new default nftables firewall.
func NewDefaultFirewall() *Firewall {
defaultSpec := firewallv1.FirewallSpec{}
return NewFirewall(&firewallv1.ClusterwideNetworkPolicyList{}, &v1.ServiceList{}, defaultSpec, nil)
return NewFirewall(&firewallv1.ClusterwideNetworkPolicyList{}, &corev1.ServiceList{}, defaultSpec, nil)
}

// NewFirewall creates a new nftables firewall object based on k8s entities
Expand Down Expand Up @@ -106,7 +106,7 @@ func (f *Firewall) Flush() error {

// Reconcile drives the nftables firewall against the desired state by comparison with the current rule file.
func (f *Firewall) Reconcile() error {
tmpFile, err := ioutil.TempFile("/var/tmp", "firewall-controller_nftables.v4")
tmpFile, err := ioutil.TempFile(filepath.Dir(f.ipv4RuleFile()), filepath.Base(f.ipv4RuleFile()))
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -106,7 +107,7 @@ func FetchGithubAssetAndChecksum(ra *github.ReleaseAsset) (io.ReadCloser, string
}

func replaceBinary(binaryReader io.ReadCloser, checksum string) error {
filename, err := copyToTempFile(binaryReader)
filename, err := copyToTempFile(binaryReader, binaryLocation)
if err != nil {
return err
}
Expand All @@ -122,8 +123,8 @@ func replaceBinary(binaryReader io.ReadCloser, checksum string) error {
return nil
}

func copyToTempFile(binaryReader io.ReadCloser) (string, error) {
file, err := ioutil.TempFile("/var/tmp", gitHubArtifact)
func copyToTempFile(binaryReader io.ReadCloser, filename string) (string, error) {
file, err := ioutil.TempFile(filepath.Dir(filename), filepath.Base(filename))
if err != nil {
return "", err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/updater/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ func Test_copyToTempFileAndValidateChecksum(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rc, _ := os.Open("./test")
tmpFile, err := copyToTempFile(rc)
tmpFile, err := copyToTempFile(rc, "./test")
if err != nil {
panic(err)
}
defer os.Remove(tmpFile)
err = validateChecksum(tmpFile, tt.args.checksum)

if (err != nil) != tt.wantErr {
Expand Down
5 changes: 0 additions & 5 deletions statik/doc.go

This file was deleted.

0 comments on commit ff41101

Please sign in to comment.