Skip to content

Commit

Permalink
Merge pull request #2077 from neogopher/backport/v0.19/pr-2075
Browse files Browse the repository at this point in the history
[v0.19] feat: Ignore updates to Rancher managed annotations (#2075)
  • Loading branch information
FabianKramm authored Aug 19, 2024
2 parents c948c5f + 21e5a1f commit 3f6db98
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 13 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,18 @@ jobs:
name: Execute test suites
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure git
run: git config --global url.https://$GH_ACCESS_TOKEN@github.com/.insteadOf https://github.com/
env:
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}

- name: download current cli
run: |
curl -L -o vcluster-current "https://github.com/loft-sh/vcluster/releases/latest/download/vcluster-linux-amd64"
VERSION=$(git ls-remote --tags origin -l 'v0.19.*' | awk -F'/' '{print $3}' | sort -V | tail -n 1)
curl -L -o vcluster-current "https://github.com/loft-sh/vcluster/releases/download/${VERSION}/vcluster-linux-amd64"
- name: Upload vcluster cli to artifact
uses: actions/upload-artifact@v4
with:
Expand Down
14 changes: 7 additions & 7 deletions cmd/vclusterctl/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,25 +298,25 @@ func (cmd *CreateCmd) Run(ctx context.Context, args []string) error {

func (cmd *CreateCmd) validateOSSFlags() error {
if cmd.Project != "" {
return fmt.Errorf("cannot use --project as you are not connected to a vCluster.Pro instance." + loginText)
return errors.New("cannot use --project as you are not connected to a vCluster.Pro instance." + loginText)
}
if cmd.Cluster != "" {
return fmt.Errorf("cannot use --cluster as you are not connected to a vCluster.Pro instance." + loginText)
return errors.New("cannot use --cluster as you are not connected to a vCluster.Pro instance." + loginText)
}
if cmd.Template != "" {
return fmt.Errorf("cannot use --template as you are not connected to a vCluster.Pro instance." + loginText)
return errors.New("cannot use --template as you are not connected to a vCluster.Pro instance." + loginText)
}
if cmd.TemplateVersion != "" {
return fmt.Errorf("cannot use --template-version as you are not connected to a vCluster.Pro instance." + loginText)
return errors.New("cannot use --template-version as you are not connected to a vCluster.Pro instance." + loginText)
}
if len(cmd.Links) > 0 {
return fmt.Errorf("cannot use --link as you are not connected to a vCluster.Pro instance." + loginText)
return errors.New("cannot use --link as you are not connected to a vCluster.Pro instance." + loginText)
}
if cmd.Params != "" {
return fmt.Errorf("cannot use --params as you are not connected to a vCluster.Pro instance." + loginText)
return errors.New("cannot use --params as you are not connected to a vCluster.Pro instance." + loginText)
}
if len(cmd.SetParams) > 0 {
return fmt.Errorf("cannot use --set-params as you are not connected to a vCluster.Pro instance." + loginText)
return errors.New("cannot use --set-params as you are not connected to a vCluster.Pro instance." + loginText)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion hack/load-testing/tests/throughput/throughput.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestThroughput(ctx context.Context, kubeClient client.Client, namespace str

err = kubeClient.Create(ctx, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
GenerateName: fmt.Sprintf("secret-test-" + random.String(10) + "-"),
GenerateName: fmt.Sprint("secret-test-" + random.String(10) + "-"),
Namespace: namespace,
},
Data: map[string][]byte{
Expand Down
70 changes: 70 additions & 0 deletions pkg/controllers/resources/nodes/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,74 @@ func TestSync(t *testing.T) {
},
},
})

basePod = &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "mypod",
},
Spec: corev1.PodSpec{
NodeName: baseName.Name,
},
}
baseNode = &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: baseName.Name,
Annotations: map[string]string{
RancherAgentPodRequestsAnnotation: "{\"pods\":\"3\"}",
RancherAgentPodLimitsAnnotation: "{\"pods\":\"10\"}",
},
},
Status: corev1.NodeStatus{
Addresses: []corev1.NodeAddress{
{
Address: GetNodeHost(baseName.Name),
Type: corev1.NodeHostName,
},
},
DaemonEndpoints: corev1.NodeDaemonEndpoints{
KubeletEndpoint: corev1.DaemonEndpoint{
Port: constants.KubeletPort,
},
},
},
}

baseVNode = &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: baseName.Name,
Annotations: map[string]string{
RancherAgentPodRequestsAnnotation: "{\"pods\":\"1\"}",
RancherAgentPodLimitsAnnotation: "{\"pods\":\"5\"}",
},
},
Status: corev1.NodeStatus{
Addresses: []corev1.NodeAddress{
{
Address: GetNodeHost(baseName.Name),
Type: corev1.NodeHostName,
},
},
DaemonEndpoints: corev1.NodeDaemonEndpoints{
KubeletEndpoint: corev1.DaemonEndpoint{
Port: constants.KubeletPort,
},
},
},
}

generictesting.RunTests(t, []*generictesting.SyncTest{
{
Name: "Nodes syncing enabled -- Ignore updates to Rancher managed annotations",
InitialPhysicalState: []runtime.Object{basePod, baseNode},
InitialVirtualState: []runtime.Object{basePod, baseVNode},
ExpectedVirtualState: map[schema.GroupVersionKind][]runtime.Object{
corev1.SchemeGroupVersion.WithKind("Node"): {baseVNode},
},
Sync: func(ctx *synccontext.RegisterContext) {
syncCtx, syncer := newFakeSyncer(t, ctx)
_, err := syncer.Sync(syncCtx, baseNode, baseVNode)
assert.NilError(t, err)
},
},
})
}
7 changes: 5 additions & 2 deletions pkg/controllers/resources/nodes/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ import (
)

var (
TaintsAnnotation = "vcluster.loft.sh/original-taints"
TaintsAnnotation = "vcluster.loft.sh/original-taints"
RancherAgentPodRequestsAnnotation = "management.cattle.io/pod-requests"
RancherAgentPodLimitsAnnotation = "management.cattle.io/pod-limits"
)

func (s *nodeSyncer) translateUpdateBackwards(pNode *corev1.Node, vNode *corev1.Node) *corev1.Node {
var updated *corev1.Node

// merge labels & taints
translatedSpec := pNode.Spec.DeepCopy()
labels, annotations := translate.ApplyMetadata(pNode.Annotations, vNode.Annotations, pNode.Labels, vNode.Labels, TaintsAnnotation)
excludeAnnotations := []string{TaintsAnnotation, RancherAgentPodRequestsAnnotation, RancherAgentPodLimitsAnnotation}
labels, annotations := translate.ApplyMetadata(pNode.Annotations, vNode.Annotations, pNode.Labels, vNode.Labels, excludeAnnotations...)

// merge taints together
oldPhysical := []string{}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package syncer

import (
"context"
"errors"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -267,7 +268,7 @@ func (r *syncerController) excludePhysical(ctx context.Context, pObj, vObj clien
if vObj != nil {
msg := "conflict: cannot sync virtual object as unmanaged physical object exists with desired name"
r.vEventRecorder.Eventf(vObj, "Warning", "SyncError", msg)
return false, fmt.Errorf(msg)
return false, errors.New(msg)
}

return true, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/setup/controller_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func InitControllerContext(
return nil, errors.Wrap(err, "get virtual cluster version")
}
nodes.FakeNodesVersion = virtualClusterVersion.GitVersion
klog.Infof("Can connect to virtual cluster with version " + virtualClusterVersion.GitVersion)
klog.Info("Can connect to virtual cluster with version " + virtualClusterVersion.GitVersion)

// create a new current namespace client
currentNamespaceClient, err := NewCurrentNamespaceClient(ctx, currentNamespace, localManager, vClusterOptions)
Expand Down

0 comments on commit 3f6db98

Please sign in to comment.