mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-14 10:24:24 -05:00
487fa1e397
* init * migration working * make tf variables with default value optional in go through ptr type * fix CI build * pr feedback * add azure targets tf * skip migration for empty targets * make instance_count optional * change role naming to dashed + add validation * make node_group.zones optional * Update cli/internal/terraform/terraform/azure/main.tf Co-authored-by: Malte Poll <1780588+malt3@users.noreply.github.com> * malte feedback --------- Co-authored-by: Malte Poll <1780588+malt3@users.noreply.github.com>
66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package role
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
)
|
|
|
|
//go:generate stringer -type=Role
|
|
|
|
// Role is a peer's role.
|
|
type Role uint
|
|
|
|
const (
|
|
// Unknown is the default value for Role and should have no meaning.
|
|
Unknown Role = iota
|
|
// ControlPlane declares this node as a Kubernetes control plane node.
|
|
ControlPlane
|
|
// Worker declares this node as a Kubernetes worker node.
|
|
Worker
|
|
)
|
|
|
|
// TFString returns the role as a string for Terraform.
|
|
func (r Role) TFString() string {
|
|
switch r {
|
|
case ControlPlane:
|
|
return "control-plane"
|
|
case Worker:
|
|
return "worker"
|
|
default:
|
|
return "unknown"
|
|
}
|
|
}
|
|
|
|
// MarshalJSON marshals the Role to JSON string.
|
|
func (r Role) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(r.String())
|
|
}
|
|
|
|
// UnmarshalJSON unmarshals the Role from JSON string.
|
|
func (r *Role) UnmarshalJSON(b []byte) error {
|
|
var roleString string
|
|
if err := json.Unmarshal(b, &roleString); err != nil {
|
|
return err
|
|
}
|
|
*r = FromString(roleString)
|
|
return nil
|
|
}
|
|
|
|
// FromString returns the Role for the given string.
|
|
func FromString(s string) Role {
|
|
switch strings.ToLower(s) {
|
|
case "controlplane", "control-plane":
|
|
return ControlPlane
|
|
case "worker":
|
|
return Worker
|
|
default:
|
|
return Unknown
|
|
}
|
|
}
|