Skip to content

Commit

Permalink
Try keep the CRD stable
Browse files Browse the repository at this point in the history
  • Loading branch information
mreiger committed Aug 30, 2024
1 parent 7b87dc0 commit a814da6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
25 changes: 13 additions & 12 deletions api/v1/clusterwidenetworkpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,22 @@ type FQDNSelector struct {
}

// IPSet stores set name association to IP addresses
type IPSet struct {
FQDN string `json:"fqdn,omitempty"`
SetName string `json:"setName,omitempty"`
IPs map[string]metav1.Time `json:"ips,omitempty"`
Version IPVersion `json:"version,omitempty"`
}

// type IPSet struct {
// FQDN string `json:"fqdn,omitempty"`
// SetName string `json:"setName,omitempty"`
// IPs []string `json:"ips,omitempty"`
// ExpirationTime metav1.Time `json:"expirationTime,omitempty"`
// Version IPVersion `json:"version,omitempty"`
// FQDN string `json:"fqdn,omitempty"`
// SetName string `json:"setName,omitempty"`
// IPs map[string]metav1.Time `json:"ips,omitempty"`
// Version IPVersion `json:"version,omitempty"`
// }

// IPSet stores set name association to IP addresses
type IPSet struct {
FQDN string `json:"fqdn,omitempty"`
SetName string `json:"setName,omitempty"`
IPs []string `json:"ips,omitempty"`
ExpirationTime metav1.Time `json:"expirationTime,omitempty"`
Version IPVersion `json:"version,omitempty"`
}

func (l *ClusterwideNetworkPolicyList) GetFQDNs() []FQDNSelector {
s := []FQDNSelector{}
for _, i := range l.Items {
Expand Down
8 changes: 3 additions & 5 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,15 @@ spec:
items:
description: IPSet stores set name association to IP addresses
properties:
expirationTime:
format: date-time
type: string
fqdn:
type: string
ips:
additionalProperties:
format: date-time
items:
type: string
type: object
type: array
setName:
type: string
version:
Expand Down
18 changes: 13 additions & 5 deletions pkg/dns/dnscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/go-logr/logr"
"github.com/google/nftables"
dnsgo "github.com/miekg/dns"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

firewallv1 "github.com/metal-stack/firewall-controller/v2/api/v1"
)
Expand Down Expand Up @@ -193,8 +193,13 @@ func (c *DNSCache) restoreSets(fqdnSets []firewallv1.IPSet) {
ipe := &ipEntry{
setName: s.SetName,
}
for ip, expirationTime := range s.IPs {
ipe.ips[ip] = expirationTime.Time
for _, ip := range s.IPs {
ipa, _, _ := strings.Cut(ip, ",")
expirationTime := time.Now()
if _, ets, found := strings.Cut(ip, ": "); found {
expirationTime.UnmarshalText([]byte(ets))

Check failure on line 200 in pkg/dns/dnscache.go

View workflow job for this annotation

GitHub Actions / Build

Error return value of `expirationTime.UnmarshalText` is not checked (errcheck)
}
ipe.ips[ipa] = expirationTime
}
switch s.Version {
case firewallv1.IPv4:
Expand Down Expand Up @@ -469,11 +474,14 @@ func createIPSetFromIPEntry(fqdn string, version firewallv1.IPVersion, entry *ip
ips := firewallv1.IPSet{
FQDN: fqdn,
SetName: entry.setName,
IPs: map[string]metav1.Time{},
IPs: []string{},
Version: version,
}
for ip, expirationTime := range entry.ips {
ips.IPs[ip] = metav1.Time{Time: expirationTime}
if et, err := expirationTime.MarshalText(); err == nil {
ip = ip + ", expiration time: " + string(et)
}
ips.IPs = append(ips.IPs, ip)
}
return ips
}
Expand Down

0 comments on commit a814da6

Please sign in to comment.