mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
remove kubeadm.alpha.kubernetes.io/cri-socket annotation when kubeadm upgrade
This commit is contained in:
parent
16da2955d0
commit
7c515cd1cb
@ -113,6 +113,10 @@ func runUploadKubeletConfig(c workflow.RunData) error {
|
|||||||
if err := patchnodephase.AnnotateCRISocket(client, cfg.NodeRegistration.Name, cfg.NodeRegistration.CRISocket); err != nil {
|
if err := patchnodephase.AnnotateCRISocket(client, cfg.NodeRegistration.Name, cfg.NodeRegistration.CRISocket); err != nil {
|
||||||
return errors.Wrap(err, "error writing CRISocket for this node")
|
return errors.Wrap(err, "error writing CRISocket for this node")
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if err := patchnodephase.RemoveCRISocketAnnotation(client, cfg.NodeRegistration.Name); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -25,6 +25,8 @@ import (
|
|||||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
|
||||||
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||||
|
"k8s.io/kubernetes/cmd/kubeadm/app/features"
|
||||||
|
patchnodephase "k8s.io/kubernetes/cmd/kubeadm/app/phases/patchnode"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/upgrade"
|
"k8s.io/kubernetes/cmd/kubeadm/app/phases/upgrade"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -69,6 +71,12 @@ func runKubeletConfigPhase(c workflow.RunData) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if features.Enabled(data.InitCfg().ClusterConfiguration.FeatureGates, features.NodeLocalCRISocket) {
|
||||||
|
if err := patchnodephase.RemoveCRISocketAnnotation(data.Client(), data.InitCfg().NodeRegistration.Name); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println("[upgrade/kubelet-config] The kubelet configuration for this node was successfully upgraded!")
|
fmt.Println("[upgrade/kubelet-config] The kubelet configuration for this node was successfully upgraded!")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
|||||||
package patchnode
|
package patchnode
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
@ -27,8 +29,7 @@ import (
|
|||||||
|
|
||||||
// AnnotateCRISocket annotates the node with the given crisocket
|
// AnnotateCRISocket annotates the node with the given crisocket
|
||||||
func AnnotateCRISocket(client clientset.Interface, nodeName string, criSocket string) error {
|
func AnnotateCRISocket(client clientset.Interface, nodeName string, criSocket string) error {
|
||||||
|
klog.V(1).Infof("[patchnode] Uploading the CRI socket %q to Node %q as an annotation", criSocket, nodeName)
|
||||||
klog.V(1).Infof("[patchnode] Uploading the CRI Socket information %q to the Node API object %q as an annotation\n", criSocket, nodeName)
|
|
||||||
|
|
||||||
return apiclient.PatchNode(client, nodeName, func(n *v1.Node) {
|
return apiclient.PatchNode(client, nodeName, func(n *v1.Node) {
|
||||||
annotateNodeWithCRISocket(n, criSocket)
|
annotateNodeWithCRISocket(n, criSocket)
|
||||||
@ -41,3 +42,20 @@ func annotateNodeWithCRISocket(n *v1.Node, criSocket string) {
|
|||||||
}
|
}
|
||||||
n.ObjectMeta.Annotations[constants.AnnotationKubeadmCRISocket] = criSocket
|
n.ObjectMeta.Annotations[constants.AnnotationKubeadmCRISocket] = criSocket
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveCRISocketAnnotation removes the crisocket annotation from a node.
|
||||||
|
func RemoveCRISocketAnnotation(client clientset.Interface, nodeName string) error {
|
||||||
|
klog.V(1).Infof("[patchnode] Removing the CRI socket annotation from Node %q", nodeName)
|
||||||
|
|
||||||
|
if err := apiclient.PatchNode(client, nodeName, removeNodeCRISocketAnnotation); err != nil {
|
||||||
|
return errors.Wrapf(err, "could not remove the CRI socket annotation from Node %q", nodeName)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeNodeCRISocketAnnotation(n *v1.Node) {
|
||||||
|
if n.ObjectMeta.Annotations == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
delete(n.ObjectMeta.Annotations, constants.AnnotationKubeadmCRISocket)
|
||||||
|
}
|
||||||
|
@ -568,7 +568,7 @@ func getNode(name string) *corev1.Node {
|
|||||||
"kubernetes.io/hostname": name,
|
"kubernetes.io/hostname": name,
|
||||||
},
|
},
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
"kubeadm.alpha.kubernetes.io/cri-socket": "dry-run-cri-socket",
|
constants.AnnotationKubeadmCRISocket: "dry-run-cri-socket",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,22 @@ var _ = Describe("nodes", func() {
|
|||||||
List(ctx, metav1.ListOptions{})
|
List(ctx, metav1.ListOptions{})
|
||||||
framework.ExpectNoError(err, "error reading nodes")
|
framework.ExpectNoError(err, "error reading nodes")
|
||||||
|
|
||||||
|
var nodeLocalCRISocketEnabled bool
|
||||||
|
cc := getClusterConfiguration(f.ClientSet)
|
||||||
|
if _, ok := cc["featureGates"]; ok {
|
||||||
|
fgCC := cc["featureGates"].(map[interface{}]interface{})
|
||||||
|
if fg, ok := fgCC["NodeLocalCRISocket"]; ok {
|
||||||
|
nodeLocalCRISocketEnabled = fg.(bool)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Checks that the nodes have the CRI socket annotation
|
// Checks that the nodes have the CRI socket annotation
|
||||||
// and that it is prefixed with a URL scheme
|
// and that it is prefixed with a URL scheme
|
||||||
for _, node := range nodes.Items {
|
for _, node := range nodes.Items {
|
||||||
gomega.Expect(node.Annotations).To(gomega.HaveKey(nodesCRISocketAnnotation))
|
if !nodeLocalCRISocketEnabled {
|
||||||
gomega.Expect(node.Annotations[nodesCRISocketAnnotation]).To(gomega.HavePrefix("unix://"))
|
gomega.Expect(node.Annotations).To(gomega.HaveKey(nodesCRISocketAnnotation))
|
||||||
|
gomega.Expect(node.Annotations[nodesCRISocketAnnotation]).To(gomega.HavePrefix("unix://"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user