Skip to content

Commit

Permalink
add instance labels.
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k1o committed Feb 26, 2022
1 parent 6f4a942 commit 62b6841
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/config/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ type Room struct {

MountsWhitelist []string

InstanceName string
InstanceUrl string
InstanceName string
InstanceUrl string
InstanceLabels []string

TraefikDomain string
TraefikEntrypoint string
Expand Down Expand Up @@ -95,6 +96,11 @@ func (Room) Init(cmd *cobra.Command) error {
return err
}

cmd.PersistentFlags().StringSlice("instance.labels", []string{}, "additional instance labels appended to a room")
if err := viper.BindPFlag("instance.labels", cmd.PersistentFlags().Lookup("instance.labels")); err != nil {
return err
}

// Traefik

cmd.PersistentFlags().String("traefik.domain", "", "traefik: domain on which will be container hosted (if empty or '*', match all; for neko-rooms as subdomain use '*.domain.tld')")
Expand Down Expand Up @@ -184,6 +190,7 @@ func (s *Room) Set() {
}

s.InstanceUrl = viper.GetString("instance.url")
s.InstanceLabels = viper.GetStringSlice("instance.labels")

s.TraefikDomain = viper.GetString("traefik.domain")
s.TraefikEntrypoint = viper.GetString("traefik.entrypoint")
Expand Down
17 changes: 17 additions & 0 deletions internal/room/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,23 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
labels[k] = v
}

// add custom instance labels
for _, label := range manager.config.InstanceLabels {
// replace dynamic values in labels
label = strings.Replace(label, "{containerName}", containerName, 1)
label = strings.Replace(label, "{roomName}", roomName, 1)
label = strings.Replace(label, "{traefikEntrypoint}", manager.config.TraefikEntrypoint, 1)

v := strings.SplitN(label, ":", 2)
if len(v) != 2 {
manager.logger.Warn().Str("label", label).Msg("invalid instance label")
continue
}

key, val := v[0], v[1]
labels[key] = val
}

//
// Set environment variables
//
Expand Down

0 comments on commit 62b6841

Please sign in to comment.