Skip to content

Commit 4e44e8f

Browse files
aleoliadamjensenbot
authored andcommitted
virtual node taints
1 parent 3c1915b commit 4e44e8f

File tree

16 files changed

+207
-93
lines changed

16 files changed

+207
-93
lines changed

apis/virtualkubelet/v1alpha1/virtualnode_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ type VirtualNodeSpec struct {
6666
ResourceQuota corev1.ResourceQuotaSpec `json:"resourceQuota,omitempty"`
6767
// Labels contains the labels to be added to the virtual node.
6868
Labels map[string]string `json:"labels,omitempty"`
69+
// Annotations contains the annotations to be added to the virtual node.
70+
Annotations map[string]string `json:"annotations,omitempty"`
71+
// Taints contains the taints to be added to the virtual node.
72+
Taints []corev1.Taint `json:"taints,omitempty"`
6973
// StorageClasses contains the list of the storage classes offered by the cluster.
7074
StorageClasses []sharingv1alpha1.StorageType `json:"storageClasses,omitempty"`
7175
// IngressClasses contains the list of the ingress classes offered by the cluster.

apis/virtualkubelet/v1alpha1/zz_generated.deepcopy.go

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deployments/liqo/crds/virtualkubelet.liqo.io_virtualnodes.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ spec:
5454
spec:
5555
description: VirtualNodeSpec defines the desired state of VirtualNode.
5656
properties:
57+
annotations:
58+
additionalProperties:
59+
type: string
60+
description: Annotations contains the annotations to be added to the
61+
virtual node.
62+
type: object
5763
clusterIdentity:
5864
description: ClusterIdentity contains the identity of the remote cluster
5965
targeted by the created virtualKubelet.
@@ -503,6 +509,34 @@ spec:
503509
- storageClassName
504510
type: object
505511
type: array
512+
taints:
513+
description: Taints contains the taints to be added to the virtual
514+
node.
515+
items:
516+
description: The node this Taint is attached to has the "effect"
517+
on any pod that does not tolerate the Taint.
518+
properties:
519+
effect:
520+
description: Required. The effect of the taint on pods that
521+
do not tolerate the taint. Valid effects are NoSchedule, PreferNoSchedule
522+
and NoExecute.
523+
type: string
524+
key:
525+
description: Required. The taint key to be applied to a node.
526+
type: string
527+
timeAdded:
528+
description: TimeAdded represents the time at which the taint
529+
was added. It is only written for NoExecute taints.
530+
format: date-time
531+
type: string
532+
value:
533+
description: The taint value corresponding to the taint key.
534+
type: string
535+
required:
536+
- effect
537+
- key
538+
type: object
539+
type: array
506540
template:
507541
description: Template contains the deployment of the created virtualKubelet.
508542
properties:

internal/liqonet/tunnel-operator/natmapping_operator_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package tunneloperator
1616

1717
import (
1818
"fmt"
19+
"slices"
1920
"strings"
2021
"time"
2122

@@ -27,7 +28,6 @@ import (
2728
"sigs.k8s.io/controller-runtime/pkg/client"
2829

2930
"github.com/liqotech/liqo/apis/net/v1alpha1"
30-
"github.com/liqotech/liqo/pkg/utils/slice"
3131
)
3232

3333
const (
@@ -179,8 +179,8 @@ var _ = Describe("NatmappingOperator", func() {
179179
Fail(fmt.Sprintf("failed to list rules in chain %s: %s", getClusterPreRoutingMappingChain(clusterID1), err))
180180
}
181181
// Should contain the rule for oldIP1 but it should not contain the rule for oldIP2
182-
if slice.ContainsString(rules, fmt.Sprintf("-d %s -j %s --to-destination %s", newIP2, DNAT, oldIP2)) &&
183-
!slice.ContainsString(rules, fmt.Sprintf("-d %s -j %s --to-destination %s", newIP1, DNAT, oldIP1)) {
182+
if slices.Contains(rules, fmt.Sprintf("-d %s -j %s --to-destination %s", newIP2, DNAT, oldIP2)) &&
183+
!slices.Contains(rules, fmt.Sprintf("-d %s -j %s --to-destination %s", newIP1, DNAT, oldIP1)) {
184184
return true
185185
}
186186
return false
@@ -222,8 +222,8 @@ var _ = Describe("NatmappingOperator", func() {
222222
Fail(fmt.Sprintf("failed to list rules in chain %s: %s", getClusterPreRoutingMappingChain(clusterID1), err))
223223
}
224224
// Cluster1 rules should contain the rule for oldIP1 and not contain the rule for oldIP2
225-
if !slice.ContainsString(cluster1Rules, fmt.Sprintf("-d %s -j %s --to-destination %s", newIP1, DNAT, oldIP1)) ||
226-
slice.ContainsString(cluster1Rules, fmt.Sprintf("-d %s -j %s --to-destination %s", newIP2, DNAT, oldIP2)) {
225+
if !slices.Contains(cluster1Rules, fmt.Sprintf("-d %s -j %s --to-destination %s", newIP1, DNAT, oldIP1)) ||
226+
slices.Contains(cluster1Rules, fmt.Sprintf("-d %s -j %s --to-destination %s", newIP2, DNAT, oldIP2)) {
227227
return false
228228
}
229229
return true
@@ -235,8 +235,8 @@ var _ = Describe("NatmappingOperator", func() {
235235
Fail(fmt.Sprintf("failed to list rules in chain %s: %s", getClusterPreRoutingMappingChain(clusterID2), err))
236236
}
237237
// Cluster2 rules should contain the rule for oldIP2 and not contain the rule for oldIP1
238-
if !slice.ContainsString(cluster2Rules, fmt.Sprintf("-d %s -j %s --to-destination %s", newIP2, DNAT, oldIP2)) ||
239-
slice.ContainsString(cluster2Rules, fmt.Sprintf("-d %s -j %s --to-destination %s", newIP1, DNAT, oldIP1)) {
238+
if !slices.Contains(cluster2Rules, fmt.Sprintf("-d %s -j %s --to-destination %s", newIP2, DNAT, oldIP2)) ||
239+
slices.Contains(cluster2Rules, fmt.Sprintf("-d %s -j %s --to-destination %s", newIP1, DNAT, oldIP1)) {
240240
return false
241241
}
242242
return true

pkg/liqoctl/completion/completion.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package completion
1717
import (
1818
"context"
1919
"fmt"
20+
"slices"
2021
"strings"
2122

2223
"github.com/spf13/cobra"
@@ -28,7 +29,6 @@ import (
2829
virtualkubeletv1alpha1 "github.com/liqotech/liqo/apis/virtualkubelet/v1alpha1"
2930
identitymanager "github.com/liqotech/liqo/pkg/identityManager"
3031
"github.com/liqotech/liqo/pkg/liqoctl/factory"
31-
"github.com/liqotech/liqo/pkg/utils/slice"
3232
utilsvirtualnode "github.com/liqotech/liqo/pkg/utils/virtualnode"
3333
)
3434

@@ -57,7 +57,7 @@ func common(ctx context.Context, f *factory.Factory, argsLimit int, retrieve ret
5757

5858
var output []string
5959
for _, value := range values {
60-
if strings.HasPrefix(value, toComplete) && !slice.ContainsString(args, value) {
60+
if strings.HasPrefix(value, toComplete) && !slices.Contains(args, value) {
6161
output = append(output, value)
6262
}
6363
}

pkg/liqoctl/install/validation.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"math/rand"
2121
"net"
2222
"net/url"
23+
"slices"
2324
"strings"
2425

2526
"github.com/goombaio/namegenerator"
@@ -28,7 +29,6 @@ import (
2829
"k8s.io/apimachinery/pkg/util/validation"
2930

3031
"github.com/liqotech/liqo/pkg/consts"
31-
"github.com/liqotech/liqo/pkg/utils/slice"
3232
)
3333

3434
// validate validates the correctness of the different parameters.
@@ -103,7 +103,7 @@ func (o *Options) validateAPIServer() error {
103103
return err
104104
}
105105

106-
if !slice.ContainsString(localhostValues, apiServerURL.Hostname()) {
106+
if !slices.Contains(localhostValues, apiServerURL.Hostname()) {
107107
o.APIServer = o.RESTConfig.Host
108108
}
109109

@@ -122,7 +122,7 @@ func (o *Options) validateAPIServer() error {
122122
return err
123123
}
124124

125-
if slice.ContainsString(localhostValues, apiServerURL.Hostname()) {
125+
if slices.Contains(localhostValues, apiServerURL.Hostname()) {
126126
return fmt.Errorf("cannot use localhost as API Server address")
127127
}
128128

pkg/liqoctl/status/local/pods.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ package statuslocal
1717
import (
1818
"context"
1919
"fmt"
20+
"slices"
2021
"strings"
2122

2223
"github.com/pterm/pterm"
2324
corev1 "k8s.io/api/core/v1"
2425
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2526
"k8s.io/apimachinery/pkg/labels"
26-
"k8s.io/utils/strings/slices"
2727

2828
"github.com/liqotech/liqo/pkg/liqoctl/output"
2929
"github.com/liqotech/liqo/pkg/liqoctl/status"
@@ -120,7 +120,7 @@ func (ps *componentState) setImages(images []string) {
120120
// addImageVersion adds an image version to the existing ones.
121121
func (ps *componentState) addImageVersion(imageVersion string) {
122122
iv := ps.getImages()
123-
if !(slice.ContainsString(iv, imageVersion)) {
123+
if !(slices.Contains(iv, imageVersion)) {
124124
iv = append(iv, imageVersion)
125125
}
126126
ps.setImages(iv)

pkg/liqoctl/status/utils/resources/resources.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package resources
1717
import (
1818
"context"
1919
"fmt"
20+
"slices"
2021
"sort"
2122

2223
"golang.org/x/exp/maps"
@@ -28,7 +29,6 @@ import (
2829
sharingv1alpha1 "github.com/liqotech/liqo/apis/sharing/v1alpha1"
2930
"github.com/liqotech/liqo/pkg/utils/getters"
3031
liqolabels "github.com/liqotech/liqo/pkg/utils/labels"
31-
"github.com/liqotech/liqo/pkg/utils/slice"
3232
)
3333

3434
// WellKnownResources contains the well known resources.
@@ -69,7 +69,7 @@ func Others(r corev1.ResourceList) map[string]string {
6969
keys := maps.Keys(r)
7070
sort.SliceStable(keys, func(i, j int) bool { return keys[i] < keys[j] })
7171
for _, k := range keys {
72-
if v, ok := (r)[k]; !slice.ContainsString(WellKnownResources, k.String()) && ok && v.Value() != 0 {
72+
if v, ok := (r)[k]; !slices.Contains(WellKnownResources, k.String()) && ok && v.Value() != 0 {
7373
result[k.String()] = v.String()
7474
}
7575
}

pkg/liqonet/ipam/ipam.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"net"
2222
"net/netip"
23+
"slices"
2324
"strings"
2425
"sync"
2526

@@ -34,7 +35,6 @@ import (
3435
liqoneterrors "github.com/liqotech/liqo/pkg/liqonet/errors"
3536
"github.com/liqotech/liqo/pkg/liqonet/natmappinginflater"
3637
liqonetutils "github.com/liqotech/liqo/pkg/liqonet/utils"
37-
"github.com/liqotech/liqo/pkg/utils/slice"
3838
)
3939

4040
// Ipam Interface.
@@ -824,11 +824,11 @@ func (liqoIPAM *IPAM) RemoveNetworkPool(network string) error {
824824
// Get cluster subnets
825825
clusterSubnets := liqoIPAM.ipamStorage.getClusterSubnets()
826826
// Check existence
827-
if exists := slice.ContainsString(ipamPools, network); !exists {
827+
if exists := slices.Contains(ipamPools, network); !exists {
828828
return fmt.Errorf("network %s is not a network pool", network)
829829
}
830830
// Cannot remove a default one
831-
if contains := slice.ContainsString(Pools, network); contains {
831+
if contains := slices.Contains(Pools, network); contains {
832832
return fmt.Errorf("cannot remove a default network pool")
833833
}
834834
// Check overlapping with cluster networks
@@ -1338,7 +1338,7 @@ func (liqoIPAM *IPAM) SetReservedSubnets(subnets []string) error {
13381338

13391339
// Free all the reserved networks not needed anymore.
13401340
for _, r := range reserved {
1341-
if !slice.ContainsString(subnets, r) {
1341+
if !slices.Contains(subnets, r) {
13421342
klog.Infof("freeing old reserved subnet %s", r)
13431343
if err := liqoIPAM.FreeReservedSubnet(r); err != nil {
13441344
return fmt.Errorf("an error occurred while freeing reserved subnet {%s}: %w", r, err)
@@ -1366,7 +1366,7 @@ func (liqoIPAM *IPAM) SetReservedSubnets(subnets []string) error {
13661366

13671367
// Reserve the newly added subnets.
13681368
for _, s := range subnets {
1369-
if slice.ContainsString(reserved, s) {
1369+
if slices.Contains(reserved, s) {
13701370
continue
13711371
}
13721372
klog.Infof("acquiring reserved subnet %s", s)

pkg/liqonet/ipam/ipamStorage.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func (ipamStorage *IPAMStorage) updateReservedSubnets(subnet, operation string)
238238
case updateOpAdd:
239239
subnets = append(subnets, subnet)
240240
case updateOpRemove:
241-
subnets = slice.RemoveString(subnets, subnet)
241+
subnets = slice.Remove(subnets, subnet)
242242
}
243243
return ipamStorage.updateConfig(reservedSubnetsUpdate, subnets)
244244
}

pkg/liqonet/iptables/iptables.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"encoding/csv"
1919
"fmt"
2020
"os"
21+
"slices"
2122
"strings"
2223
"sync"
2324

@@ -31,7 +32,6 @@ import (
3132
"github.com/liqotech/liqo/pkg/liqonet/errors"
3233
liqoipset "github.com/liqotech/liqo/pkg/liqonet/ipset"
3334
liqonetutils "github.com/liqotech/liqo/pkg/liqonet/utils"
34-
"github.com/liqotech/liqo/pkg/utils/slice"
3535
)
3636

3737
const (
@@ -305,7 +305,7 @@ func (h IPTHandler) deleteLiqoChains() error {
305305
func (h IPTHandler) deleteChainsInTable(table string, chains, chainsToBeRemoved []string) error {
306306
for _, chain := range chainsToBeRemoved {
307307
// Check existence of chain
308-
if slice.ContainsString(chains, chain) {
308+
if slices.Contains(chains, chain) {
309309
continue
310310
}
311311
// Chain does exist, then delete it.
@@ -474,7 +474,7 @@ func (h IPTHandler) deleteRulesInChain(chain string, rules []IPTableRule) error
474474
return fmt.Errorf("unable to list rules in chain %s (table %s): %w", chain, table, err)
475475
}
476476
for _, rule := range rules {
477-
if !slice.ContainsString(existingRules, rule.String()) {
477+
if !slices.Contains(existingRules, rule.String()) {
478478
continue
479479
}
480480
// Rule exists, then delete it
@@ -503,9 +503,9 @@ func (h IPTHandler) removeChainsPerCluster(clusterID string) error {
503503
// For each cluster chain, check if it exists.
504504
// If it does exist, then remove it. Otherwise do nothing.
505505
for _, chain := range chains {
506-
if getTableFromChain(chain) == natTable && slice.ContainsString(existingChainsNAT, chain) {
506+
if getTableFromChain(chain) == natTable && slices.Contains(existingChainsNAT, chain) {
507507
// Check if chain exists
508-
if !slice.ContainsString(existingChainsNAT, chain) {
508+
if !slices.Contains(existingChainsNAT, chain) {
509509
continue
510510
}
511511
if err := h.Ipt.ClearAndDeleteChain(natTable, chain); err != nil {
@@ -514,8 +514,8 @@ func (h IPTHandler) removeChainsPerCluster(clusterID string) error {
514514
klog.Infof("Deleted chain %s in table %s", chain, getTableFromChain(chain))
515515
continue
516516
}
517-
if getTableFromChain(chain) == filterTable && slice.ContainsString(existingChainsFilter, chain) {
518-
if !slice.ContainsString(existingChainsFilter, chain) {
517+
if getTableFromChain(chain) == filterTable && slices.Contains(existingChainsFilter, chain) {
518+
if !slices.Contains(existingChainsFilter, chain) {
519519
continue
520520
}
521521
if err := h.Ipt.ClearChain(filterTable, chain); err != nil {

0 commit comments

Comments
 (0)