Skip to content

Commit aa61692

Browse files
populate region from region service using annotation - I don't love it
1 parent c75a738 commit aa61692

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright 2025 the Unikorn Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package observabilityagent
18+
19+
const (
20+
// RegionNameAnnotation is set on clusters to pass the friendly region name to the
21+
// observability agent values generator.
22+
RegionNameAnnotation = "observability-agent.unikorn-cloud.org/region-name"
23+
)

pkg/provisioners/helmapplications/observabilityagent/provisioner.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ func (p *Provisioner) Values(ctx context.Context, version unikornv1core.Semantic
4747

4848
values := map[string]any{
4949
"clusterName": cluster.Name,
50-
"region": "glo1",
50+
"region": cluster.Annotations[RegionNameAnnotation],
5151
"environment": "dev",
5252
}
5353

54+
if values["region"] == "" {
55+
values["region"] = cluster.Spec.RegionID
56+
}
57+
5458
return values, nil
5559
}

pkg/provisioners/managers/cluster/provisioner.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import (
5757
"github.com/unikorn-cloud/kubernetes/pkg/provisioners/helmapplications/openstackcloudprovider"
5858
"github.com/unikorn-cloud/kubernetes/pkg/provisioners/helmapplications/openstackplugincindercsi"
5959
"github.com/unikorn-cloud/kubernetes/pkg/provisioners/helmapplications/vcluster"
60+
regionutil "github.com/unikorn-cloud/kubernetes/pkg/util/region"
6061
regionclient "github.com/unikorn-cloud/region/pkg/client"
6162
regionapi "github.com/unikorn-cloud/region/pkg/openapi"
6263

@@ -644,6 +645,31 @@ func (p *Provisioner) identityOptions(ctx context.Context, client regionapi.Clie
644645
return options, nil
645646
}
646647

648+
func (p *Provisioner) annotateRegion(ctx context.Context, client regionapi.ClientWithResponsesInterface) error {
649+
organizationID, ok := p.cluster.Labels[coreconstants.OrganizationLabel]
650+
if !ok {
651+
return fmt.Errorf("%w: %s", ErrAnnotation, coreconstants.OrganizationLabel)
652+
}
653+
654+
region, err := regionutil.Region(ctx, client, organizationID, p.cluster.Spec.RegionID)
655+
if err != nil {
656+
return err
657+
}
658+
659+
if p.cluster.Annotations == nil {
660+
p.cluster.Annotations = map[string]string{}
661+
}
662+
663+
name := region.Metadata.Name
664+
if name == "" {
665+
name = p.cluster.Spec.RegionID
666+
}
667+
668+
p.cluster.Annotations[observabilityagent.RegionNameAnnotation] = name
669+
670+
return nil
671+
}
672+
647673
// Provision implements the Provision interface.
648674
func (p *Provisioner) Provision(ctx context.Context) error {
649675
// The cluster manager is provisioned asynchronously as it takes a good minute
@@ -665,6 +691,10 @@ func (p *Provisioner) Provision(ctx context.Context) error {
665691
return err
666692
}
667693

694+
if err := p.annotateRegion(clientContext, client); err != nil {
695+
return err
696+
}
697+
668698
provisioner, err := p.getProvisioner(ctx, options, true)
669699
if err != nil {
670700
return err

0 commit comments

Comments
 (0)