Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Suffixing placement group names in Hetzner #42

Merged
merged 1 commit into from
Jan 11, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var (
)

func main() {
flag.BoolVar(&verbose, "verbose", true, "Enable verbose logging")
flag.BoolVar(&verbose, "verbose", false, "Enable verbose logging")

flag.StringVar(&metricsAddr, "metrics-bind-address", "localhost:8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
Expand All @@ -73,7 +73,7 @@ func main() {
flag.StringVar(&watchNamespace, "namespace", "", "Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.")

opts := zap.Options{
Development: true,
Development: verbose,
}
opts.BindFlags(flag.CommandLine)
flag.Parse()
Expand Down
9 changes: 7 additions & 2 deletions pkg/services/hcloud/placementgroup/placementgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package placementgroup

import (
"context"
"fmt"
"strings"

"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/pkg/errors"
Expand All @@ -35,6 +37,8 @@ type Service struct {
scope *scope.ClusterScope
}

const pgDelimiter = "-"

// NewService creates new service object.
func NewService(scope *scope.ClusterScope) *Service {
return &Service{
Expand Down Expand Up @@ -88,9 +92,10 @@ func (s *Service) Reconcile(ctx context.Context) (err error) {
}
}
if !foundInStatus {
name := fmt.Sprintf("%s%s%s", s.scope.HetznerCluster.Name, pgDelimiter, pgSpec.Name)
clusterTagKey := infrav1.ClusterTagKey(s.scope.HetznerCluster.Name)
if _, _, err := s.scope.HCloudClient().CreatePlacementGroup(ctx, hcloud.PlacementGroupCreateOpts{
Name: pgSpec.Name,
Name: name,
Type: hcloud.PlacementGroupType(pgSpec.Type),
Labels: map[string]string{clusterTagKey: string(infrav1.ResourceLifecycleOwned)},
}); err != nil {
Expand Down Expand Up @@ -154,7 +159,7 @@ func (s *Service) apiToStatus(placementGroups []*hcloud.PlacementGroup) (status
status = append(status, infrav1.HCloudPlacementGroupStatus{
ID: pg.ID,
Server: pg.Servers,
Name: pg.Name,
Name: strings.Split(pg.Name, pgDelimiter)[1],
Type: string(pg.Type),
})
}
Expand Down