Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions builtin/capkk/roles/uninstall/cri/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
- include_tasks: uninstall_cridockerd.yaml
when:
- .cri.container_manager | eq "docker"
- .kube_version | semverCompare ">=v1.24.0"
- .cridockerd_version | empty | not

- name: Delete residue files
- name: Delete cri residue files
command: |
rm -f /usr/local/bin/crictl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
rm -rf /etc/systemd/system/containerd.service*
systemctl daemon-reload

- name: Delete residue files
- name: Delete containerd residue files
command: |
rm -rf {{ .cri.containerd.data_root }}
rm -rf /etc/containerd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
rm -rf /etc/systemd/system/cri-dockerd.service*
systemctl daemon-reload

- name: Delete residue files
- name: Delete cri-dockerd residue files
command: |
rm -rf /etc/cri-dockerd
rm -f /usr/local/bin/cri-dockerd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- name: Uninstall containerd
include_tasks: uninstall_containerd.yaml

- name: Delete residue files
- name: Delete docker residue files
command: |
rm -rf {{ .cri.docker.data_root }}
rm -rf /etc/docker
Expand Down
3 changes: 3 additions & 0 deletions builtin/core/roles/precheck/env_check/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@

- include_tasks: nfs.yaml
tags: ["nfs"]

- include_tasks: image_registry.yaml
tags: ["image_registry"]
5 changes: 2 additions & 3 deletions builtin/core/roles/uninstall/cri/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
include_tasks: uninstall_docker.yaml
when: .cri.container_manager | eq "docker"

# install cridockerd
# uninstall cridockerd
- include_tasks: uninstall_cridockerd.yaml
when:
- .cri.container_manager | eq "docker"
- .kube_version | semverCompare ">=v1.24.0"
- .cridockerd_version | empty | not

- name: Delete residue files
- name: Delete cri residue files
command: |
rm -f /usr/local/bin/crictl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
rm -rf /etc/systemd/system/containerd.service*
systemctl daemon-reload

- name: Delete residue files
- name: Delete containerd residue files
command: |
rm -rf {{ .cri.containerd.data_root }}
rm -rf /etc/containerd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
rm -rf /etc/systemd/system/cri-dockerd.service*
systemctl daemon-reload

- name: Delete residue files
- name: Delete cri-dockerd residue files
command: |
rm -rf /etc/cri-dockerd
rm -f /usr/local/bin/cri-dockerd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- name: Uninstall containerd
include_tasks: uninstall_containerd.yaml

- name: Delete residue files
- name: Delete docker residue files
command: |
rm -rf {{ .cri.docker.data_root }}
rm -rf /etc/docker
Expand Down
14 changes: 7 additions & 7 deletions cmd/kk/app/builtin/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewDeleteCommand() *cobra.Command {
// Add subcommands for cluster, nodes, and image registry deletion
cmd.AddCommand(newDeleteClusterCommand())
cmd.AddCommand(newDeleteNodesCommand())
cmd.AddCommand(newDeleteImageRegistryCommand())
cmd.AddCommand(newDeleteRegistryCommand())

return cmd
}
Expand Down Expand Up @@ -108,18 +108,18 @@ func newDeleteNodesCommand() *cobra.Command {
return cmd
}

// newDeleteImageRegistryCommand creates a new command for deleting the image registry created by kubekey.
// newDeleteRegistryCommand creates a new command for deleting the image registry created by kubekey.
// It uses the delete_image_registry.yaml playbook to remove the image registry and optionally its container runtime.
func newDeleteImageRegistryCommand() *cobra.Command {
func newDeleteRegistryCommand() *cobra.Command {
// Initialize options for deleting the image registry
o := builtin.NewDeleteImageRegistryOptions()
o := builtin.NewDeleteRegistryOptions()

cmd := &cobra.Command{
Use: "image_registry",
Short: "Delete a image_registry which create by kubekey.",
Use: "registry",
Short: "Delete a image registry which create by kubekey.",
RunE: func(cmd *cobra.Command, args []string) error {
// Complete the configuration and create a playbook for deleting the image registry
playbook, err := o.Complete(cmd, []string{"playbooks/delete_image_registry.yaml"})
playbook, err := o.Complete(cmd, []string{"playbooks/delete_registry.yaml"})
if err != nil {
return err
}
Expand Down
45 changes: 9 additions & 36 deletions cmd/kk/app/options/builtin/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,50 +218,35 @@ func (o *DeleteNodesOptions) completeConfig(nodes []string) error {
}

// ======================================================================================
// delete image_registry
// delete registry
// ======================================================================================

// NewDeleteImageRegistryOptions creates a new DeleteImageRegistryOptions with default values
func NewDeleteImageRegistryOptions() *DeleteImageRegistryOptions {
// NewDeleteRegistryOptions creates a new DeleteRegistryOptions with default values
func NewDeleteRegistryOptions() *DeleteRegistryOptions {
// set default value for DeleteImageRegistryOptions
o := &DeleteImageRegistryOptions{
o := &DeleteRegistryOptions{
CommonOptions: options.NewCommonOptions(),
Kubernetes: defaultKubeVersion,
}
// Set the function to get the config for the specified Kubernetes version
o.CommonOptions.GetConfigFunc = func() (*kkcorev1.Config, error) {
data, err := getConfig(o.Kubernetes)
if err != nil {
return nil, err
}
config := &kkcorev1.Config{}
return config, errors.Wrapf(yaml.Unmarshal(data, config), "failed to unmarshal local configFile for kube_version: %q.", o.Kubernetes)
}
// Set the function to get the inventory
o.CommonOptions.GetInventoryFunc = getInventory

return o
}

// DeleteImageRegistryOptions contains options for deleting an image_registry created by kubekey
type DeleteImageRegistryOptions struct {
// DeleteRegistryOptions contains options for deleting an image_registry created by kubekey
type DeleteRegistryOptions struct {
options.CommonOptions
// Kubernetes version which the cluster will install.
Kubernetes string
}

// Flags returns the flag sets for DeleteImageRegistryOptions
func (o *DeleteImageRegistryOptions) Flags() cliflag.NamedFlagSets {
func (o *DeleteRegistryOptions) Flags() cliflag.NamedFlagSets {
fss := o.CommonOptions.Flags()
kfs := fss.FlagSet("config")
// Add a flag for specifying the Kubernetes version
kfs.StringVar(&o.Kubernetes, "with-kubernetes", o.Kubernetes, fmt.Sprintf("Specify a supported version of kubernetes. default is %s", o.Kubernetes))

return fss
}

// Complete validates and completes the DeleteImageRegistryOptions configuration
func (o *DeleteImageRegistryOptions) Complete(cmd *cobra.Command, args []string) (*kkcorev1.Playbook, error) {
func (o *DeleteRegistryOptions) Complete(cmd *cobra.Command, args []string) (*kkcorev1.Playbook, error) {
// Initialize playbook metadata for deleting image registry
playbook := &kkcorev1.Playbook{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -291,17 +276,5 @@ func (o *DeleteImageRegistryOptions) Complete(cmd *cobra.Command, args []string)
}

// Complete config specific to delete image registry
return playbook, o.completeConfig()
}

// completeConfig updates the configuration with container manager settings
func (o *DeleteImageRegistryOptions) completeConfig() error {
// If kube_version is not set in config, set it to the specified Kubernetes version
if _, ok, _ := unstructured.NestedFieldNoCopy(o.CommonOptions.Config.Value(), "kube_version"); !ok {
if err := unstructured.SetNestedField(o.CommonOptions.Config.Value(), o.Kubernetes, "kube_version"); err != nil {
return errors.Wrapf(err, "failed to set %q to config", "kube_version")
}
}

return nil
return playbook, nil
}
4 changes: 2 additions & 2 deletions pkg/executor/task_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func (e *taskExecutor) Exec(ctx context.Context) error {
// runTaskLoop runs a task in a loop until it completes or times out.
// It periodically reconciles the task status and executes the task when it enters the running phase.
func (e *taskExecutor) runTaskLoop(ctx context.Context) error {
klog.V(5).InfoS("begin run task", "task", ctrlclient.ObjectKeyFromObject(e.task))
defer klog.V(5).InfoS("end run task", "task", ctrlclient.ObjectKeyFromObject(e.task))
klog.V(3).InfoS("begin run task", "task", ctrlclient.ObjectKeyFromObject(e.task))
defer klog.V(3).InfoS("end run task", "task", ctrlclient.ObjectKeyFromObject(e.task))

// Add role prefix to log output if role annotation exists
var roleLog string
Expand Down