Skip to content

Commit 246d38c

Browse files
authored
Set the autoupdate singleton names (#52751)
1 parent 3d58949 commit 246d38c

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

tool/tctl/common/resource_command.go

+51-5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import (
5050
dbobjectv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/dbobject/v1"
5151
dbobjectimportrulev1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/dbobjectimportrule/v1"
5252
devicepb "github.com/gravitational/teleport/api/gen/proto/go/teleport/devicetrust/v1"
53+
headerv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/header/v1"
5354
loginrulepb "github.com/gravitational/teleport/api/gen/proto/go/teleport/loginrule/v1"
5455
machineidv1pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/machineid/v1"
5556
pluginsv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/plugins/v1"
@@ -3756,6 +3757,13 @@ func (rc *ResourceCommand) createAutoUpdateConfig(ctx context.Context, client *a
37563757
return trace.Wrap(err)
37573758
}
37583759

3760+
if config.GetMetadata() == nil {
3761+
config.Metadata = &headerv1.Metadata{}
3762+
}
3763+
if config.GetMetadata().GetName() == "" {
3764+
config.Metadata.Name = types.MetaNameAutoUpdateConfig
3765+
}
3766+
37593767
if rc.IsForced() {
37603768
_, err = client.UpsertAutoUpdateConfig(ctx, config)
37613769
} else {
@@ -3774,6 +3782,14 @@ func (rc *ResourceCommand) updateAutoUpdateConfig(ctx context.Context, client *a
37743782
if err != nil {
37753783
return trace.Wrap(err)
37763784
}
3785+
3786+
if config.GetMetadata() == nil {
3787+
config.Metadata = &headerv1.Metadata{}
3788+
}
3789+
if config.GetMetadata().GetName() == "" {
3790+
config.Metadata.Name = types.MetaNameAutoUpdateConfig
3791+
}
3792+
37773793
if _, err := client.UpdateAutoUpdateConfig(ctx, config); err != nil {
37783794
return trace.Wrap(err)
37793795
}
@@ -3787,6 +3803,13 @@ func (rc *ResourceCommand) createAutoUpdateVersion(ctx context.Context, client *
37873803
return trace.Wrap(err)
37883804
}
37893805

3806+
if version.GetMetadata() == nil {
3807+
version.Metadata = &headerv1.Metadata{}
3808+
}
3809+
if version.GetMetadata().GetName() == "" {
3810+
version.Metadata.Name = types.MetaNameAutoUpdateVersion
3811+
}
3812+
37903813
if rc.IsForced() {
37913814
_, err = client.UpsertAutoUpdateVersion(ctx, version)
37923815
} else {
@@ -3805,6 +3828,14 @@ func (rc *ResourceCommand) updateAutoUpdateVersion(ctx context.Context, client *
38053828
if err != nil {
38063829
return trace.Wrap(err)
38073830
}
3831+
3832+
if version.GetMetadata() == nil {
3833+
version.Metadata = &headerv1.Metadata{}
3834+
}
3835+
if version.GetMetadata().GetName() == "" {
3836+
version.Metadata.Name = types.MetaNameAutoUpdateVersion
3837+
}
3838+
38083839
if _, err := client.UpdateAutoUpdateVersion(ctx, version); err != nil {
38093840
return trace.Wrap(err)
38103841
}
@@ -3813,15 +3844,22 @@ func (rc *ResourceCommand) updateAutoUpdateVersion(ctx context.Context, client *
38133844
}
38143845

38153846
func (rc *ResourceCommand) createAutoUpdateAgentRollout(ctx context.Context, client *authclient.Client, raw services.UnknownResource) error {
3816-
version, err := services.UnmarshalProtoResource[*autoupdatev1pb.AutoUpdateAgentRollout](raw.Raw)
3847+
rollout, err := services.UnmarshalProtoResource[*autoupdatev1pb.AutoUpdateAgentRollout](raw.Raw)
38173848
if err != nil {
38183849
return trace.Wrap(err)
38193850
}
38203851

3852+
if rollout.GetMetadata() == nil {
3853+
rollout.Metadata = &headerv1.Metadata{}
3854+
}
3855+
if rollout.GetMetadata().GetName() == "" {
3856+
rollout.Metadata.Name = types.MetaNameAutoUpdateAgentRollout
3857+
}
3858+
38213859
if rc.IsForced() {
3822-
_, err = client.UpsertAutoUpdateAgentRollout(ctx, version)
3860+
_, err = client.UpsertAutoUpdateAgentRollout(ctx, rollout)
38233861
} else {
3824-
_, err = client.CreateAutoUpdateAgentRollout(ctx, version)
3862+
_, err = client.CreateAutoUpdateAgentRollout(ctx, rollout)
38253863
}
38263864
if err != nil {
38273865
return trace.Wrap(err)
@@ -3832,11 +3870,19 @@ func (rc *ResourceCommand) createAutoUpdateAgentRollout(ctx context.Context, cli
38323870
}
38333871

38343872
func (rc *ResourceCommand) updateAutoUpdateAgentRollout(ctx context.Context, client *authclient.Client, raw services.UnknownResource) error {
3835-
version, err := services.UnmarshalProtoResource[*autoupdatev1pb.AutoUpdateAgentRollout](raw.Raw)
3873+
rollout, err := services.UnmarshalProtoResource[*autoupdatev1pb.AutoUpdateAgentRollout](raw.Raw)
38363874
if err != nil {
38373875
return trace.Wrap(err)
38383876
}
3839-
if _, err := client.UpdateAutoUpdateAgentRollout(ctx, version); err != nil {
3877+
3878+
if rollout.GetMetadata() == nil {
3879+
rollout.Metadata = &headerv1.Metadata{}
3880+
}
3881+
if rollout.GetMetadata().GetName() == "" {
3882+
rollout.Metadata.Name = types.MetaNameAutoUpdateAgentRollout
3883+
}
3884+
3885+
if _, err := client.UpdateAutoUpdateAgentRollout(ctx, rollout); err != nil {
38403886
return trace.Wrap(err)
38413887
}
38423888
fmt.Println("autoupdate_version has been updated")

0 commit comments

Comments
 (0)