Skip to content

Commit 7c515cd

Browse files
committed
remove kubeadm.alpha.kubernetes.io/cri-socket annotation when kubeadm upgrade
1 parent 16da295 commit 7c515cd

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

cmd/kubeadm/app/cmd/phases/upgrade/apply/uploadconfig.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ func runUploadKubeletConfig(c workflow.RunData) error {
113113
if err := patchnodephase.AnnotateCRISocket(client, cfg.NodeRegistration.Name, cfg.NodeRegistration.CRISocket); err != nil {
114114
return errors.Wrap(err, "error writing CRISocket for this node")
115115
}
116+
} else {
117+
if err := patchnodephase.RemoveCRISocketAnnotation(client, cfg.NodeRegistration.Name); err != nil {
118+
return err
119+
}
116120
}
117121

118122
return nil

cmd/kubeadm/app/cmd/phases/upgrade/kubeletconfig.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
2626
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
2727
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
28+
"k8s.io/kubernetes/cmd/kubeadm/app/features"
29+
patchnodephase "k8s.io/kubernetes/cmd/kubeadm/app/phases/patchnode"
2830
"k8s.io/kubernetes/cmd/kubeadm/app/phases/upgrade"
2931
)
3032

@@ -69,6 +71,12 @@ func runKubeletConfigPhase(c workflow.RunData) error {
6971
return err
7072
}
7173

74+
if features.Enabled(data.InitCfg().ClusterConfiguration.FeatureGates, features.NodeLocalCRISocket) {
75+
if err := patchnodephase.RemoveCRISocketAnnotation(data.Client(), data.InitCfg().NodeRegistration.Name); err != nil {
76+
return err
77+
}
78+
}
79+
7280
fmt.Println("[upgrade/kubelet-config] The kubelet configuration for this node was successfully upgraded!")
7381
return nil
7482
}

cmd/kubeadm/app/phases/patchnode/patchnode.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package patchnode
1818

1919
import (
20+
"github.com/pkg/errors"
21+
2022
"k8s.io/api/core/v1"
2123
clientset "k8s.io/client-go/kubernetes"
2224
"k8s.io/klog/v2"
@@ -27,8 +29,7 @@ import (
2729

2830
// AnnotateCRISocket annotates the node with the given crisocket
2931
func AnnotateCRISocket(client clientset.Interface, nodeName string, criSocket string) error {
30-
31-
klog.V(1).Infof("[patchnode] Uploading the CRI Socket information %q to the Node API object %q as an annotation\n", criSocket, nodeName)
32+
klog.V(1).Infof("[patchnode] Uploading the CRI socket %q to Node %q as an annotation", criSocket, nodeName)
3233

3334
return apiclient.PatchNode(client, nodeName, func(n *v1.Node) {
3435
annotateNodeWithCRISocket(n, criSocket)
@@ -41,3 +42,20 @@ func annotateNodeWithCRISocket(n *v1.Node, criSocket string) {
4142
}
4243
n.ObjectMeta.Annotations[constants.AnnotationKubeadmCRISocket] = criSocket
4344
}
45+
46+
// RemoveCRISocketAnnotation removes the crisocket annotation from a node.
47+
func RemoveCRISocketAnnotation(client clientset.Interface, nodeName string) error {
48+
klog.V(1).Infof("[patchnode] Removing the CRI socket annotation from Node %q", nodeName)
49+
50+
if err := apiclient.PatchNode(client, nodeName, removeNodeCRISocketAnnotation); err != nil {
51+
return errors.Wrapf(err, "could not remove the CRI socket annotation from Node %q", nodeName)
52+
}
53+
return nil
54+
}
55+
56+
func removeNodeCRISocketAnnotation(n *v1.Node) {
57+
if n.ObjectMeta.Annotations == nil {
58+
return
59+
}
60+
delete(n.ObjectMeta.Annotations, constants.AnnotationKubeadmCRISocket)
61+
}

cmd/kubeadm/app/util/apiclient/dryrun.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ func getNode(name string) *corev1.Node {
568568
"kubernetes.io/hostname": name,
569569
},
570570
Annotations: map[string]string{
571-
"kubeadm.alpha.kubernetes.io/cri-socket": "dry-run-cri-socket",
571+
constants.AnnotationKubeadmCRISocket: "dry-run-cri-socket",
572572
},
573573
},
574574
}

test/e2e_kubeadm/nodes_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,22 @@ var _ = Describe("nodes", func() {
5252
List(ctx, metav1.ListOptions{})
5353
framework.ExpectNoError(err, "error reading nodes")
5454

55+
var nodeLocalCRISocketEnabled bool
56+
cc := getClusterConfiguration(f.ClientSet)
57+
if _, ok := cc["featureGates"]; ok {
58+
fgCC := cc["featureGates"].(map[interface{}]interface{})
59+
if fg, ok := fgCC["NodeLocalCRISocket"]; ok {
60+
nodeLocalCRISocketEnabled = fg.(bool)
61+
}
62+
}
63+
5564
// Checks that the nodes have the CRI socket annotation
5665
// and that it is prefixed with a URL scheme
5766
for _, node := range nodes.Items {
58-
gomega.Expect(node.Annotations).To(gomega.HaveKey(nodesCRISocketAnnotation))
59-
gomega.Expect(node.Annotations[nodesCRISocketAnnotation]).To(gomega.HavePrefix("unix://"))
67+
if !nodeLocalCRISocketEnabled {
68+
gomega.Expect(node.Annotations).To(gomega.HaveKey(nodesCRISocketAnnotation))
69+
gomega.Expect(node.Annotations[nodesCRISocketAnnotation]).To(gomega.HavePrefix("unix://"))
70+
}
6071
}
6172
})
6273

0 commit comments

Comments
 (0)