Skip to content

Commit

Permalink
Always set cluster-id flag for Protokube
Browse files Browse the repository at this point in the history
  • Loading branch information
hakman committed Apr 24, 2022
1 parent a700e1b commit bb8bd5a
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 46 deletions.
3 changes: 3 additions & 0 deletions nodeup/pkg/model/protokube.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func (t *ProtokubeBuilder) buildSystemdService() (*nodetasks.Service, error) {

// ProtokubeFlags are the flags for protokube
type ProtokubeFlags struct {
ClusterID *string `json:"clusterID,omitempty" flag:"cluster-id"`
Channels []string `json:"channels,omitempty" flag:"channels"`
Cloud *string `json:"cloud,omitempty" flag:"cloud"`
Containerized *bool `json:"containerized,omitempty" flag:"containerized"`
Expand Down Expand Up @@ -195,6 +196,8 @@ func (t *ProtokubeBuilder) ProtokubeFlags(k8sVersion semver.Version) (*Protokube
Master: b(t.IsMaster),
}

f.ClusterID = fi.String(t.Cluster.ObjectMeta.Name)

zone := t.Cluster.Spec.DNSZone
if zone != "" {
if strings.Contains(zone, ".") {
Expand Down
2 changes: 1 addition & 1 deletion nodeup/pkg/model/tests/protokube/tasks-protokube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ definition: |
Documentation=https://kops.sigs.k8s.io
[Service]
ExecStart=/opt/kops/bin/protokube --bootstrap-master-node-labels=true --cloud=aws --containerized=false --dns-internal-suffix=.internal.minimal.example.com --dns=aws-route53 --master=true --node-name=master.hostname.invalid --remove-dns-names=etcd-master-us-test-1a.internal.minimal.example.com,etcd-events-master-us-test-1a.internal.minimal.example.com --v=4 --zone=*/Z1AFAKE1ZON3YO
ExecStart=/opt/kops/bin/protokube --bootstrap-master-node-labels=true --cloud=aws --cluster-id=minimal.example.com --containerized=false --dns-internal-suffix=.internal.minimal.example.com --dns=aws-route53 --master=true --node-name=master.hostname.invalid --remove-dns-names=etcd-master-us-test-1a.internal.minimal.example.com,etcd-events-master-us-test-1a.internal.minimal.example.com --v=4 --zone=*/Z1AFAKE1ZON3YO
EnvironmentFile=/etc/sysconfig/protokube
Restart=always
RestartSec=3s
Expand Down
30 changes: 4 additions & 26 deletions protokube/cmd/protokube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func run() error {
flag.BoolVar(&containerized, "containerized", containerized, "Set if we are running containerized.")
flag.BoolVar(&master, "master", master, "Whether or not this node is a master")
flag.StringVar(&cloud, "cloud", "aws", "CloudProvider we are using (aws,digitalocean,gce,openstack)")
flag.StringVar(&clusterID, "cluster-id", clusterID, "Cluster ID")
flag.StringVar(&clusterID, "cluster-id", clusterID, "Cluster ID for internal domain names")
flag.StringVar(&dnsInternalSuffix, "dns-internal-suffix", dnsInternalSuffix, "DNS suffix for internal domain names")
flags.IntVar(&dnsUpdateInterval, "dns-update-interval", 5, "Configure interval at which to update DNS records.")
flag.StringVar(&flagChannels, "channels", flagChannels, "channels to install")
Expand Down Expand Up @@ -112,10 +112,6 @@ func run() error {
volumes = awsVolumes
internalIP = awsVolumes.InternalIP()

if clusterID == "" {
clusterID = awsVolumes.ClusterID()
}

} else if cloud == "digitalocean" {
doVolumes, err := protokube.NewDOVolumes()
if err != nil {
Expand All @@ -129,13 +125,6 @@ func run() error {
os.Exit(1)
}

if clusterID == "" {
clusterID, err = protokube.GetClusterID()
if err != nil {
klog.Errorf("Error getting clusterid: %s", err)
os.Exit(1)
}
}
} else if cloud == "gce" {
gceVolumes, err := protokube.NewGCEVolumes()
if err != nil {
Expand All @@ -146,9 +135,6 @@ func run() error {
volumes = gceVolumes
internalIP = gceVolumes.InternalIP()

if clusterID == "" {
clusterID = gceVolumes.ClusterID()
}
} else if cloud == "openstack" {
klog.Info("Initializing openstack volumes")
osVolumes, err := protokube.NewOpenstackVolumes()
Expand All @@ -159,9 +145,6 @@ func run() error {
volumes = osVolumes
internalIP = osVolumes.InternalIP()

if clusterID == "" {
clusterID = osVolumes.ClusterID()
}
} else if cloud == "azure" {
klog.Info("Initializing Azure volumes")
azureVolumes, err := protokube.NewAzureVolumes()
Expand All @@ -172,25 +155,20 @@ func run() error {
volumes = azureVolumes
internalIP = azureVolumes.InternalIP()

if clusterID == "" {
clusterID = azureVolumes.ClusterID()
}
} else {
klog.Errorf("Unknown cloud %q", cloud)
os.Exit(1)
}

if clusterID == "" {
return fmt.Errorf("cluster-id is required (cannot be determined from cloud)")
}
klog.Infof("cluster-id: %s", clusterID)

if internalIP == nil {
klog.Errorf("Cannot determine internal IP")
os.Exit(1)
}

if dnsInternalSuffix == "" {
if clusterID == "" {
return fmt.Errorf("cluster-id is required when dns-internal-suffix is not set")
}
// TODO: Maybe only master needs DNS?
dnsInternalSuffix = ".internal." + clusterID
klog.Infof("Setting dns-internal-suffix to %q", dnsInternalSuffix)
Expand Down
4 changes: 0 additions & 4 deletions protokube/pkg/protokube/aws_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ func NewAWSVolumes() (*AWSVolumes, error) {
return a, nil
}

func (a *AWSVolumes) ClusterID() string {
return a.clusterTag
}

func (a *AWSVolumes) InternalIP() net.IP {
return a.internalIP
}
Expand Down
5 changes: 0 additions & 5 deletions protokube/pkg/protokube/azure_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ func NewAzureVolumes() (*AzureVolumes, error) {
}, nil
}

// ClusterID implements Volumes ClusterID.
func (a *AzureVolumes) ClusterID() string {
return a.clusterTag
}

// InstanceID implements Volumes InstanceID.
func (a *AzureVolumes) InstanceID() string {
return a.instanceID
Expand Down
5 changes: 0 additions & 5 deletions protokube/pkg/protokube/gce_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ func NewGCEVolumes() (*GCEVolumes, error) {
return a, nil
}

// ClusterID implements Volumes ClusterID
func (a *GCEVolumes) ClusterID() string {
return a.clusterName
}

// Project returns the current GCE project
func (a *GCEVolumes) Project() string {
return a.project
Expand Down
5 changes: 0 additions & 5 deletions protokube/pkg/protokube/openstack_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ func NewOpenstackVolumes() (*OpenstackVolumes, error) {
return a, nil
}

// ClusterID implements Volumes ClusterID
func (a *OpenstackVolumes) ClusterID() string {
return a.meta.UserMeta.ClusterName
}

// Project returns the current GCE project
func (a *OpenstackVolumes) Project() string {
return a.meta.ProjectID
Expand Down

0 comments on commit bb8bd5a

Please sign in to comment.