From 305a0a9a6007517700942342cd32c2a0866938fc Mon Sep 17 00:00:00 2001 From: Vadym Popov Date: Thu, 28 Nov 2024 12:01:35 -0500 Subject: [PATCH] Add remove tctl command for AutoUpdateConfig and AutoUpdateVersion (#49532) --- tool/tctl/common/resource_command.go | 12 ++++++++++++ tool/tctl/common/resource_command_test.go | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/tool/tctl/common/resource_command.go b/tool/tctl/common/resource_command.go index 7bd410e86f3ea..4dc78b9f6a4fd 100644 --- a/tool/tctl/common/resource_command.go +++ b/tool/tctl/common/resource_command.go @@ -1460,6 +1460,8 @@ func (rc *ResourceCommand) Delete(ctx context.Context, client *authclient.Client types.KindInstaller, types.KindUIConfig, types.KindNetworkRestrictions, + types.KindAutoUpdateConfig, + types.KindAutoUpdateVersion, } if !slices.Contains(singletonResources, rc.ref.Kind) && (rc.ref.Kind == "" || rc.ref.Name == "") { return trace.BadParameter("provide a full resource name to delete, for example:\n$ tctl rm cluster/east\n") @@ -1843,6 +1845,16 @@ func (rc *ResourceCommand) Delete(ctx context.Context, client *authclient.Client return trace.Wrap(err) } fmt.Printf("SPIFFE federation %q has been deleted\n", rc.ref.Name) + case types.KindAutoUpdateConfig: + if err := client.DeleteAutoUpdateConfig(ctx); err != nil { + return trace.Wrap(err) + } + fmt.Printf("AutoUpdateConfig has been deleted\n") + case types.KindAutoUpdateVersion: + if err := client.DeleteAutoUpdateVersion(ctx); err != nil { + return trace.Wrap(err) + } + fmt.Printf("AutoUpdateVersion has been deleted\n") default: return trace.BadParameter("deleting resources of type %q is not supported", rc.ref.Kind) } diff --git a/tool/tctl/common/resource_command_test.go b/tool/tctl/common/resource_command_test.go index be15e22a8f9b6..347d073e68b5e 100644 --- a/tool/tctl/common/resource_command_test.go +++ b/tool/tctl/common/resource_command_test.go @@ -2226,6 +2226,12 @@ version: v1 protocmp.IgnoreFields(&headerv1.Metadata{}, "id", "revision"), protocmp.Transform(), )) + + // Delete the resource + _, err = runResourceCommand(t, clt, []string{"rm", types.KindAutoUpdateConfig}) + require.NoError(t, err) + _, err = runResourceCommand(t, clt, []string{"get", types.KindAutoUpdateConfig}) + require.ErrorContains(t, err, "autoupdate_config \"autoupdate-config\" doesn't exist") } func testCreateAutoUpdateVersion(t *testing.T, clt *authclient.Client) { @@ -2261,6 +2267,12 @@ version: v1 protocmp.IgnoreFields(&headerv1.Metadata{}, "id", "revision"), protocmp.Transform(), )) + + // Delete the resource + _, err = runResourceCommand(t, clt, []string{"rm", types.KindAutoUpdateVersion}) + require.NoError(t, err) + _, err = runResourceCommand(t, clt, []string{"get", types.KindAutoUpdateVersion}) + require.ErrorContains(t, err, "autoupdate_version \"autoupdate-version\" doesn't exist") } func TestPluginResourceWrapper(t *testing.T) {