Skip to content

Commit e9eda6e

Browse files
committed
Use SetLabels() to set ForwardingRules labels
The ForwardingRules resource requires that the SetLabels() method be used to add the labels after the resource has been created.
1 parent 3c2e7de commit e9eda6e

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

cloud/services/compute/loadbalancers/reconcile.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,18 @@ func (s *Service) createOrGetForwardingRule(ctx context.Context, lbname string,
579579
}
580580
}
581581

582+
// Labels on ForwardingRules must be added after resource is created
583+
labels := s.scope.AdditionalLabels()
584+
if !labels.Equals(forwarding.Labels) {
585+
setLabelsRequest := &compute.GlobalSetLabelsRequest{
586+
LabelFingerprint: forwarding.LabelFingerprint,
587+
Labels: labels,
588+
}
589+
if err = s.forwardingrules.SetLabels(ctx, key, setLabelsRequest); err != nil {
590+
return nil, err
591+
}
592+
}
593+
582594
return forwarding, nil
583595
}
584596

@@ -622,6 +634,18 @@ func (s *Service) createOrGetRegionalForwardingRule(ctx context.Context, lbname
622634
}
623635
}
624636

637+
// Labels on ForwardingRules must be added after resource is created
638+
labels := s.scope.AdditionalLabels()
639+
if !labels.Equals(forwarding.Labels) {
640+
setLabelsRequest := &compute.RegionSetLabelsRequest{
641+
LabelFingerprint: forwarding.LabelFingerprint,
642+
Labels: labels,
643+
}
644+
if err = s.regionalforwardingrules.SetLabels(ctx, key, setLabelsRequest); err != nil {
645+
return nil, err
646+
}
647+
}
648+
625649
return forwarding, nil
626650
}
627651

cloud/services/compute/loadbalancers/service.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ type forwardingrulesInterface interface {
4444
Get(ctx context.Context, key *meta.Key, options ...k8scloud.Option) (*compute.ForwardingRule, error)
4545
Insert(ctx context.Context, key *meta.Key, obj *compute.ForwardingRule, options ...k8scloud.Option) error
4646
Delete(ctx context.Context, key *meta.Key, options ...k8scloud.Option) error
47+
SetLabels(ctx context.Context, key *meta.Key, obj *compute.GlobalSetLabelsRequest, options ...k8scloud.Option) error
48+
}
49+
50+
type regionalforwardingrulesInterface interface {
51+
Get(ctx context.Context, key *meta.Key, options ...k8scloud.Option) (*compute.ForwardingRule, error)
52+
Insert(ctx context.Context, key *meta.Key, obj *compute.ForwardingRule, options ...k8scloud.Option) error
53+
Delete(ctx context.Context, key *meta.Key, options ...k8scloud.Option) error
54+
SetLabels(ctx context.Context, key *meta.Key, obj *compute.RegionSetLabelsRequest, options ...k8scloud.Option) error
4755
}
4856

4957
type healthchecksInterface interface {
@@ -89,7 +97,7 @@ type Service struct {
8997
backendservices backendservicesInterface
9098
regionalbackendservices backendservicesInterface
9199
forwardingrules forwardingrulesInterface
92-
regionalforwardingrules forwardingrulesInterface
100+
regionalforwardingrules regionalforwardingrulesInterface
93101
healthchecks healthchecksInterface
94102
regionalhealthchecks healthchecksInterface
95103
instancegroups instancegroupsInterface

0 commit comments

Comments
 (0)