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

fix device tags #31

Merged
merged 1 commit into from
May 7, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions api/v1alpha3/packetcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ type PacketClusterSpec struct {
ProjectID string `json:"projectID"`
}

// APIEndpoint represents a reachable Kubernetes API endpoint.
type APIEndpoint struct {
// The hostname on which the API server is serving.
Host string `json:"host"`
// The port on which the API server is serving.
Port int `json:"port"`
}

// PacketClusterStatus defines the observed state of PacketCluster
type PacketClusterStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Expand All @@ -40,6 +48,9 @@ type PacketClusterStatus struct {
// Ready denotes that the cluster (infrastructure) is ready.
// +optional
Ready bool `json:"ready"`
// APIEndpoints represents the endpoints to communicate with the control plane.
// +optional
APIEndpoints []APIEndpoint `json:"apiEndpoints,omitempty"`
}

// +kubebuilder:subresource:status
Expand Down
22 changes: 21 additions & 1 deletion api/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions controllers/packetcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controllers

import (
"context"
"time"

"github.com/go-logr/logr"
"github.com/pkg/errors"
Expand Down Expand Up @@ -68,6 +69,14 @@ func (r *PacketClusterReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, re
return ctrl.Result{}, err
}

if cluster == nil {
logger.Info("OwenerCluster is not set yet. Requeuing...")
return ctrl.Result{
Requeue: true,
RequeueAfter: 2 * time.Second,
}, nil
}

// Create the cluster scope
clusterScope, err := scope.NewClusterScope(scope.ClusterScopeParams{
Logger: logger,
Expand Down
3 changes: 2 additions & 1 deletion controllers/packetmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
} else {
tags = append(tags, infrastructurev1alpha3.WorkerTag)
}

name := machineScope.Name()
dev, err = r.PacketClient.NewDevice(name, clusterScope.PacketCluster.Spec.ProjectID, machineScope.PacketMachine.Spec)
dev, err = r.PacketClient.NewDevice(name, clusterScope.PacketCluster.Spec.ProjectID, machineScope.PacketMachine.Spec, tags)
if err != nil {
errs := fmt.Errorf("failed to create machine %s: %v", name, err)
machineScope.SetErrorReason(capierrors.CreateMachineError)
Expand Down
5 changes: 3 additions & 2 deletions pkg/cloud/packet/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@ func (p *PacketClient) GetDevice(deviceID string) (*packngo.Device, error) {
return dev, err
}

func (p *PacketClient) NewDevice(hostname, project string, spec infrav1.PacketMachineSpec) (*packngo.Device, error) {
func (p *PacketClient) NewDevice(hostname, project string, spec infrav1.PacketMachineSpec, extraTags []string) (*packngo.Device, error) {
tags := append(spec.Tags, extraTags...)
serverCreateOpts := &packngo.DeviceCreateRequest{
Hostname: hostname,
ProjectID: project,
Facility: spec.Facility,
BillingCycle: spec.BillingCycle,
Plan: spec.MachineType,
OS: spec.OS,
Tags: spec.Tags,
Tags: tags,
}

dev, _, err := p.Client.Devices.Create(serverCreateOpts)
Expand Down
28 changes: 24 additions & 4 deletions templates/cluster-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
kind: KubeadmConfig
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
metadata:
name: my-control-plane1-config
name: "${CLUSTER_NAME}-control-plane1-config"
spec:
initConfiguration:
nodeRegistration:
Expand Down Expand Up @@ -46,7 +46,7 @@ spec:
configRef:
kind: KubeadmConfig
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
name: my-control-plane1-config
name: "${CLUSTER_NAME}-control-plane1-config"
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
kind: PacketMachine
Expand Down Expand Up @@ -78,7 +78,7 @@ spec:
configRef:
kind: KubeadmConfig
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
name: my-control-plane1-config
name: "${CLUSTER_NAME}-worker0-config"
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
kind: PacketMachine
Expand Down Expand Up @@ -110,7 +110,7 @@ spec:
configRef:
kind: KubeadmConfig
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
name: my-control-plane1-config
name: "${CLUSTER_NAME}-worker1-config"
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
kind: PacketMachine
Expand All @@ -129,3 +129,23 @@ spec:
sshKeys:
- "${SSH_KEY}"
tags: []
---
kind: KubeadmConfig
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
metadata:
name: "${CLUSTER_NAME}-worker1-config"
spec:
joinConfiguration:
nodeRegistration:
kubeletExtraArgs:
eviction-hard: nodefs.available<0%,nodefs.inodesFree<0%,imagefs.available<0%
---
kind: KubeadmConfig
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
metadata:
name: "${CLUSTER_NAME}-worker0-config"
spec:
joinConfiguration:
nodeRegistration:
kubeletExtraArgs:
eviction-hard: nodefs.available<0%,nodefs.inodesFree<0%,imagefs.available<0%