Skip to content

Commit

Permalink
Merge pull request #190 from deitch/packet
Browse files Browse the repository at this point in the history
Support for Packet provider as a driver
  • Loading branch information
prashanth26 authored Dec 22, 2018
2 parents 50e5528 + 88db6ea commit c5c9bac
Show file tree
Hide file tree
Showing 79 changed files with 5,988 additions and 275 deletions.
307 changes: 272 additions & 35 deletions Gopkg.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ required = [
name = "github.com/gophercloud/gophercloud"
revision = "fe85f9519740a5b5c09ecb0909609b58e59e5dec"

[[constraint]]
name = "github.com/packethost/packngo"
revision = "b3b45f1b4979af3ace1cd5450768ab387b40ae5b"

[prune]
unused-packages = true
go-tests = true
Expand Down
5 changes: 5 additions & 0 deletions cmd/machine-controller-manager-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ func main() {
machineclass = &class
classKind = "AlicloudMachineClass"

case "PacketMachineClass", "packet":
class := v1alpha1.PacketMachineClass{}
machineclass = &class
classKind = "PacketMachineClass"

default:
log.Fatalf("Unknown class kind %s", classKind)
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/machine-controller-manager/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var awsGVR = schema.GroupVersionResource{Group: "machine.sapcloud.io", Version:
var azureGVR = schema.GroupVersionResource{Group: "machine.sapcloud.io", Version: "v1alpha1", Resource: "azuremachineclasses"}
var gcpGVR = schema.GroupVersionResource{Group: "machine.sapcloud.io", Version: "v1alpha1", Resource: "gcpmachineclasses"}
var alicloudGVR = schema.GroupVersionResource{Group: "machine.sapcloud.io", Version: "v1alpha1", Resource: "alicloudmachineclasses"}
var packetGVR = schema.GroupVersionResource{Group: "machine.sapcloud.io", Version: "v1alpha1", Resource: "packetmachineclasses"}

// Run runs the MCMServer. This should never exit.
func Run(s *options.MCMServer) error {
Expand Down Expand Up @@ -221,7 +222,7 @@ func StartControllers(s *options.MCMServer,
glog.Fatal(err)
}

if availableResources[awsGVR] || availableResources[azureGVR] || availableResources[gcpGVR] || availableResources[openStackGVR] || availableResources[alicloudGVR] {
if availableResources[awsGVR] || availableResources[azureGVR] || availableResources[gcpGVR] || availableResources[openStackGVR] || availableResources[alicloudGVR] || availableResources[packetGVR] {
glog.V(5).Infof("Creating shared informers; resync interval: %v", s.MinResyncPeriod)

controlMachineInformerFactory := machineinformers.NewFilteredSharedInformerFactory(
Expand Down Expand Up @@ -259,6 +260,7 @@ func StartControllers(s *options.MCMServer,
machineSharedInformers.AzureMachineClasses(),
machineSharedInformers.GCPMachineClasses(),
machineSharedInformers.AlicloudMachineClasses(),
machineSharedInformers.PacketMachineClasses(),
machineSharedInformers.Machines(),
machineSharedInformers.MachineSets(),
machineSharedInformers.MachineDeployments(),
Expand All @@ -278,7 +280,7 @@ func StartControllers(s *options.MCMServer,
go machineController.Run(int(s.ConcurrentNodeSyncs), stop)

} else {
return fmt.Errorf("unable to start machine controller: API GroupVersion %q or %q or %q or %q or %q is not available; found %#v", awsGVR, azureGVR, gcpGVR, openStackGVR, alicloudGVR, availableResources)
return fmt.Errorf("unable to start machine controller: API GroupVersion %q or %q or %q or %q or %q or %q is not available; found %#v", awsGVR, azureGVR, gcpGVR, openStackGVR, alicloudGVR, packetGVR, availableResources)
}

select {}
Expand Down
11 changes: 11 additions & 0 deletions kubernetes/Secrets/packet-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Sample secret for GCP

apiVersion: v1
kind: Secret
metadata:
name: test-secret # Name of the secret
namespace: default # Namespace of the secret
data:
userData: "encoded-cloud-config" # packet cloud config file (base64 encoded)
packetAPIKey: "{...}" # packet API key (base64 encoded)
type: Opaque
17 changes: 17 additions & 0 deletions kubernetes/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ spec:

---

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: packetmachineclasses.machine.sapcloud.io
spec:
group: machine.sapcloud.io
version: v1alpha1
scope: Namespaced
names:
kind: PacketMachineClass
plural: packetmachineclasses
singular: packetmachineclass
shortNames:
- packetcls

---

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
Expand Down
1 change: 1 addition & 0 deletions kubernetes/deployment/control-cluster-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ rules:
- gcpmachineclasses
- openstackmachineclasses
- alicloudmachineclasses
- packetmachineclasses
- machinedeployments
- machines
- machinesets
Expand Down
23 changes: 23 additions & 0 deletions kubernetes/machine_classes/packet-machine-class.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Sample Packet machine class

apiVersion: machine.sapcloud.io/v1alpha1
kind: PacketMachineClass
metadata:
name: test-packet # Name of packet machine class goes here
namespace: default # Namespace in which the machine class is to be deployed
spec:
projectID: f40c6787-5ac0-657e-9fe4-62d433c5df11 # UUID of a project with which you have rights
OS: alpine_3 # OS ID or slug goes here
facility:
- EWR1 # Facilities wherein the server can be deployed. Can be one, two or many, or the keyword "any"
- AMS1
machineType: x1.small # Type of packet bare-metal machine
tags:
Name: sample-machine-name # Name tag that can be used to identify a machine at Packet
kubernetes.io/cluster/YOUR_CLUSTER_NAME: "1" # This is mandatory as the safety controller uses this tag to identify VMs created by this controller.
kubernetes.io/role/YOUR_ROLE_NAME: "1" # This is mandatory as the safety controller uses this tag to identify VMs created by by this controller.
tag1: tag1-value # A set of additional tags attached to a machine (optional)
tag2: tag2-value # A set of additional tags attached to a machine (optional)
secretRef: # Secret pointing to a secret which contains the provider secret and cloudconfig
namespace: default # Namespace
name: test-secret # Name of the secret
3 changes: 3 additions & 0 deletions pkg/apis/machine/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&AlicloudMachineClass{},
&AlicloudMachineClassList{},

&PacketMachineClass{},
&PacketMachineClassList{},

&Machine{},
&MachineList{},

Expand Down
53 changes: 53 additions & 0 deletions pkg/apis/machine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1176,3 +1176,56 @@ type AlicloudSystemDisk struct {
Category string
Size int
}

/********************** PacketMachineClass APIs ***************/

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// PacketMachineClass TODO
type PacketMachineClass struct {
// +optional
metav1.ObjectMeta

// +optional
metav1.TypeMeta

// +optional
Spec PacketMachineClassSpec
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// PacketMachineClassList is a collection of PacketMachineClasses.
type PacketMachineClassList struct {
// +optional
metav1.TypeMeta

// +optional
metav1.ListMeta

// +optional
Items []PacketMachineClass
}

// PacketMachineClassSpec is the specification of a cluster.
type PacketMachineClassSpec struct {
Facility []string // required
MachineType string // required
OS string // required
ProjectID string // required
BillingCycle string
Tags map[string]string
SSHKeys []PacketSSHKeySpec
UserData string

SecretRef *corev1.SecretReference

// TODO add more here
}

// PacketSSHKeySpec represents a single ssh key
type PacketSSHKeySpec struct {
ID string
Fingerprint string
}
3 changes: 3 additions & 0 deletions pkg/apis/machine/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&AlicloudMachineClass{},
&AlicloudMachineClassList{},

&PacketMachineClass{},
&PacketMachineClassList{},

&Machine{},
&MachineList{},

Expand Down
54 changes: 54 additions & 0 deletions pkg/apis/machine/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,9 @@ const (
AlicloudAccessKeyID string = "alicloudAccessKeyID"
// AlicloudAccessKeySecret is a constant for a key name that is part of the Alibaba cloud credentials.
AlicloudAccessKeySecret string = "alicloudAccessKeySecret"

// PacketAPIKey is a constant for a key name that is part of the Packet cloud credentials
PacketAPIKey string = "packetAPIKey"
)

/********************** AlicloudMachineClass APIs ***************/
Expand Down Expand Up @@ -1217,3 +1220,54 @@ type AlicloudSystemDisk struct {
Category string `json:"category"`
Size int `json:"size"`
}

/********************** PacketMachineClass APIs ***************/

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// PacketMachineClass TODO
type PacketMachineClass struct {
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`

// +optional
metav1.TypeMeta `json:",inline"`

// +optional
Spec PacketMachineClassSpec `json:"spec,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// PacketMachineClassList is a collection of PacketMachineClasses.
type PacketMachineClassList struct {
// +optional
metav1.TypeMeta `json:",inline"`

// +optional
metav1.ListMeta `json:"metadata,omitempty"`

// +optional
Items []PacketMachineClass `json:"items"`
}

// PacketMachineClassSpec is the specification of a cluster.
type PacketMachineClassSpec struct {
Facility []string `json:"facility"`
MachineType string `json:"machineType"`
BillingCycle string `json:"billingCycle"`
OS string `json:"OS"`
ProjectID string `json:"projectID"`
Tags map[string]string `json:"tags,omitempty"`
SSHKeys []PacketSSHKeySpec `json:"sshKeys,omitempty"`
UserData string `json:"userdata,omitempty"`

SecretRef *corev1.SecretReference `json:"secretRef,omitempty"`
}

// PacketSSHKeySpec describes ssh keys for packet
type PacketSSHKeySpec struct {
ID string `json:"id"`
Fingerprint string `json:"fingerprint"`
}
Loading

0 comments on commit c5c9bac

Please sign in to comment.