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

update packngo to 0.5.1 #39

Merged
merged 6 commits into from
Dec 13, 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
6 changes: 5 additions & 1 deletion .github/workflows/charts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install QEMU
run: DEBIAN_FRONTEND=noninteractive sudo apt-get install -yq --no-install-recommends binfmt-support qemu-user-static
env:
DEBIAN_FRONTEND=noninteractive
run: |
sudo apt update -q
sudo apt install -yq --no-install-recommends binfmt-support qemu-user-static

- name: Register QEMU with Docker
run: docker run --rm --privileged hypriot/qemu-register
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Crossplane Equinix Metal Provider

![](https://img.shields.io/badge/Stability-Maintained-green.svg)
[![GitHub release](https://img.shields.io/github/release/packethost/crossplane-provider-equinix-metal/all.svg?style=flat-square)](https://github.com/packethost/crossplane-provider-equinix-metal/releases)
[![Go Report Card](https://goreportcard.com/badge/github.com/packethost/crossplane-provider-equinix-metal)](https://goreportcard.com/report/github.com/packethost/crossplane-provider-equinix-metal)
[![Slack](https://slack.equinixmetal.com/badge.svg)](https://slack.equinixmetal.com)
[![Twitter Follow](https://img.shields.io/twitter/follow/packethost.svg?style=social&label=Follow)](https://twitter.com/intent/follow?screen_name=equinixmetal)
![](https://img.shields.io/badge/Stability-Maintained-green.svg)

## Overview

[From Crossplane's Provider documentation](https://crossplane.io/docs/v0.12/introduction/providers.html):
[From Crossplane's Provider documentation](https://crossplane.io/docs/v0.14/introduction/providers.html):

> Providers extend Crossplane to enable infrastructure resource provisioning. In order to provision a resource, a Custom Resource Definition(CRD) needs to be registered in your Kubernetes cluster and its controller should be watching the Custom Resources those CRDs define. Provider packages contain many Custom Resource Definitions and their controllers.

Expand Down Expand Up @@ -40,7 +43,7 @@ helm install crossplane --namespace crossplane-system crossplane-alpha/crossplan
### Install the Crossplane CLI

```console
curl -sL https://raw.githubusercontent.com/crossplane/crossplane/release-0.13/install.sh | sh
curl -sL https://raw.githubusercontent.com/crossplane/crossplane/release-0.14/install.sh | sh
```

## Install the Equinix Metal Provider
Expand Down Expand Up @@ -149,7 +152,7 @@ secret/devices-creds deleted

## Roadmap and Stability

This Crossplane provider is alpha quality, not officially supported, and not intended for production use.
This Crossplane provider is alpha quality and not intended for production use.

Equinix Metal devices, virtual networks, and ports can be managed through this provider, which provides basic integration. Advanced features like BGP, VPN, Volumes are not currently planned. If you are interested in these features, please let us know by [opening issues](#report-a-bug) and [reaching out](#contact).

Expand Down
18 changes: 14 additions & 4 deletions apis/server/v1alpha2/device_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1alpha2

import (
runtimev1alpha1 "github.com/crossplane/crossplane-runtime/apis/core/v1alpha1"
"github.com/packethost/packngo"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -97,6 +96,15 @@ type DeviceList struct {
Items []Device `json:"items"`
}

// IPAddress is a packngo.IPAddressCreateRequest used for managing IP addresses
// at Device, at creation and observer time.
type IPAddress struct {
AddressFamily int `json:"address_family"`
Public bool `json:"public"`
CIDR int `json:"cidr,omitempty"`
Reservations []string `json:"ip_reservations,omitempty"`
}

// DeviceParameters define the desired state of an Equinix Metal device.
// https://metal.equinix.com/developers/api/#devices
//
Expand Down Expand Up @@ -171,9 +179,11 @@ type DeviceParameters struct {
// +optional
Features map[string]string `json:"features,omitempty"`

// +immutable
// +optional
IPAddresses []packngo.IPAddressCreateRequest `json:"ipAddresses,omitempty"`
displague marked this conversation as resolved.
Show resolved Hide resolved
// IPAddresses will be attached to the device. These addresses can be drawn
// from existing reservations.
//
// +immutable +optional
IPAddresses []IPAddress `json:"ipAddresses,omitempty"`
}

// DeviceObservation is used to reflect in the Kubernetes API, the observed
Expand Down
27 changes: 24 additions & 3 deletions apis/server/v1alpha2/zz_generated.deepcopy.go

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

3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ require (
github.com/google/go-cmp v0.5.0
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/packethost/packngo v0.2.0
github.com/packethost/packngo v0.5.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.1.0 // indirect
github.com/spf13/cobra v1.0.0 // indirect
github.com/stretchr/testify v1.5.1 // indirect
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
golang.org/x/net v0.0.0-20200904194848-62affa334b73 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
Expand Down
13 changes: 11 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dnaeon/go-vcr v1.0.1 h1:r8L/HqC0Hje5AXMu1ooW8oyQyOFv4GxqpL0nRP7SLLY=
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
Expand Down Expand Up @@ -222,7 +224,13 @@ github.com/grpc-ecosystem/grpc-gateway v1.3.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpg
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-getter v1.4.0/go.mod h1:7qxyCd8rBfcShwsvxgIguu4KbS3l8bUCwg2Umn7RjeY=
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.6.6 h1:HJunrbHTDDbBb/ay4kxa1n+dLmttUlnP3V9oNE4hmsM=
github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I=
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
Expand Down Expand Up @@ -319,8 +327,8 @@ github.com/onsi/gomega v1.8.1 h1:C5Dqfs/LeauYDX0jJXIe2SWmwCbGzx9yF8C8xy3Lh34=
github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/packethost/packngo v0.2.0 h1:mSlzOof8PsOWCy78sBMt/PwMJTEjjQ/rRvMixu4Nm6c=
github.com/packethost/packngo v0.2.0/go.mod h1:RQHg5xR1F614BwJyepfMqrKN+32IH0i7yX+ey43rEeQ=
github.com/packethost/packngo v0.5.1 h1:y+jWcMnyArP3hVZRsBkAXTLhokuqdYg6JUmkshX2SMk=
github.com/packethost/packngo v0.5.1/go.mod h1:aRxUEV1TprXVcWr35v8tNYgZMjv7FHaInXx224vF2fc=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down Expand Up @@ -441,6 +449,7 @@ golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975 h1:/Tl7pH94bvbAAHBdZJT947M/+gp0+CqQXDtMRC0fseo=
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200420201142-3c4aac89819a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM=
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand Down
8 changes: 8 additions & 0 deletions package/crds/server.metal.equinix.com_devices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,18 @@ spec:
hostname:
type: string
ipAddresses:
description: IPAddresses will be attached to the device. These addresses can be drawn from existing reservations.
items:
description: IPAddress is a packngo.IPAddressCreateRequest used for managing IP addresses at Device, at creation and observer time.
properties:
address_family:
type: integer
cidr:
type: integer
ip_reservations:
items:
type: string
type: array
public:
type: boolean
required:
Expand Down
7 changes: 4 additions & 3 deletions package/crossplane.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ metadata:
Available resources and their fields can be found in the [CRD
Docs](https://doc.crds.dev/github.com/packethost/crossplane-provider-equinix-metal).

If you encounter an issue please reach out on the #equinix-metal channel
in [slack.crossplane.io](https://slack.crossplane.io) and create an issue
in the
If you encounter an issue please reach out on the #community channel in
[slack.equinixmetal.com](https://slack.equinixmetal.com) and create an
issue in the
[packethost/crossplane-provider-equinix-metal](https://github.com/packethost/crossplane-provider-equinix-metal)
repo.
iconData: PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDQuMDYgOTQuMyI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOiNlYzIwMjc7fS5jbHMtMntmaWxsOiM2ZTZmNzI7fTwvc3R5bGU+PC9kZWZzPjxwb2x5Z29uIGNsYXNzPSJjbHMtMSIgcG9pbnRzPSI3MS40NyA2LjUgNzEuNDcgMTkuMDQgNjguNjEgMjAuMDQgNjguNjEgNS41IDYwLjAxIDIuNSA2MC4wMSAyMy4wNCA1Ny4xNSAyNC4wNCA1Ny4xNSAxLjUgNTIuODUgMCA0OC41NSAxLjUgNDguNTUgMjQuMDQgNDUuNjkgMjMuMDQgNDUuNjkgMi41IDM3LjEgNS41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MS44NGgtOC41WiIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTI1My45NiAtMzQ1LjYxKSIvPjxyZWN0IGNsYXNzPSJjbHMtMiIgeT0iNjUuNTIiIHdpZHRoPSIxMDQuMDYiIGhlaWdodD0iMC41Ii8+PC9zdmc+
displague marked this conversation as resolved.
Show resolved Hide resolved

spec:
controller:
Expand Down
20 changes: 17 additions & 3 deletions pkg/clients/device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const (
type Client interface {
Get(deviceID string, getOpt *packngo.GetOptions) (*packngo.Device, *packngo.Response, error)
Create(*packngo.DeviceCreateRequest) (*packngo.Device, *packngo.Response, error)
Delete(deviceID string) (*packngo.Response, error)
Delete(deviceID string, force bool) (*packngo.Response, error)
Update(string, *packngo.DeviceUpdateRequest) (*packngo.Device, *packngo.Response, error)
}

Expand All @@ -50,6 +50,7 @@ type Client interface {
type PortsClient interface {
DeviceToNetworkType(string, string) (*packngo.Device, error)
DeviceNetworkType(string) (string, error)
ConvertDevice(*packngo.Device, string) error
displague marked this conversation as resolved.
Show resolved Hide resolved
}

// build-time test that the interface is implemented
Expand Down Expand Up @@ -91,6 +92,16 @@ func NewClient(ctx context.Context, credentials []byte, projectID string) (Clien

// CreateFromDevice return packngo.DeviceCreateRequest created from Kubernetes
func CreateFromDevice(d *v1alpha2.Device, projectID string) *packngo.DeviceCreateRequest {
ips := []packngo.IPAddressCreateRequest{}
for _, ip := range d.Spec.ForProvider.IPAddresses {
ips = append(ips, packngo.IPAddressCreateRequest{
AddressFamily: ip.AddressFamily,
Public: ip.Public,
CIDR: ip.CIDR,
Reservations: ip.Reservations,
})
}

return &packngo.DeviceCreateRequest{
Hostname: emptyIfNil(d.Spec.ForProvider.Hostname),
Plan: d.Spec.ForProvider.Plan,
Expand All @@ -100,6 +111,7 @@ func CreateFromDevice(d *v1alpha2.Device, projectID string) *packngo.DeviceCreat
ProjectID: projectID,
UserData: emptyIfNil(d.Spec.ForProvider.UserData),
Tags: d.Spec.ForProvider.Tags,
IPAddresses: ips,
}
}

Expand Down Expand Up @@ -178,7 +190,8 @@ func LateInitialize(in *v1alpha2.DeviceParameters, device *packngo.Device) {
in.Plan = clients.LateInitializeString(in.Plan, &device.Plan.Slug)
}

in.NetworkType = clients.LateInitializeStringPtr(in.NetworkType, &device.NetworkType)
networkType := device.GetNetworkType()
in.NetworkType = clients.LateInitializeStringPtr(in.NetworkType, &networkType)

in.Hostname = clients.LateInitializeStringPtr(in.Hostname, &device.Hostname)
in.BillingCycle = clients.LateInitializeStringPtr(in.BillingCycle, &device.BillingCycle)
Expand Down Expand Up @@ -213,7 +226,8 @@ func LateInitialize(in *v1alpha2.DeviceParameters, device *packngo.Device) {
// modified in place without deleting and recreating the instance, which are
// immutable.
func IsUpToDate(d *v1alpha2.Device, p *packngo.Device) (upToDate bool, networkTypeUpToDate bool) {
networkIsUpToDate := nilOrEqualStr(d.Spec.ForProvider.NetworkType, p.NetworkType)
networkType := p.GetNetworkType()
networkIsUpToDate := nilOrEqualStr(d.Spec.ForProvider.NetworkType, networkType)

if !nilOrEqualStr(d.Spec.ForProvider.Hostname, p.Hostname) {
return false, networkIsUpToDate
Expand Down
16 changes: 13 additions & 3 deletions pkg/clients/device/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ var _ device.ClientWithDefaults = &MockClient{}

// MockClient is a fake implementation of packngo.Client.
type MockClient struct {
// mock the Client for Devices

MockCreate func(createRequest *packngo.DeviceCreateRequest) (*packngo.Device, *packngo.Response, error)
MockUpdate func(deviceID string, createRequest *packngo.DeviceUpdateRequest) (*packngo.Device, *packngo.Response, error)
MockDelete func(deviceID string) (*packngo.Response, error)
MockDelete func(deviceID string, force bool) (*packngo.Response, error)
MockGet func(deviceID string, getOpt *packngo.GetOptions) (*packngo.Device, *packngo.Response, error)

// mock the PortsClient

MockDeviceToNetworkType func(deviceID string, networkType string) (*packngo.Device, error)
MockDeviceNetworkType func(deviceID string) (string, error)
MockConvertDevice func(*packngo.Device, string) error

MockGetProjectID func(string) string
MockGetFacilityID func(string) string
Expand All @@ -49,8 +54,8 @@ func (c *MockClient) Update(deviceID string, createRequest *packngo.DeviceUpdate
}

// Delete calls the MockClient's MockDelete function.
func (c *MockClient) Delete(deviceID string) (*packngo.Response, error) {
return c.MockDelete(deviceID)
func (c *MockClient) Delete(deviceID string, force bool) (*packngo.Response, error) {
return c.MockDelete(deviceID, false)
}

// Get calls the MockClient's MockGet function.
Expand All @@ -77,3 +82,8 @@ func (c *MockClient) GetFacilityID(id string) string {
func (c *MockClient) GetProjectID(id string) string {
return c.MockGetProjectID(id)
}

// ConvertDevice calls the MockClient's MockConvertDevice function.
func (c *MockClient) ConvertDevice(d *packngo.Device, networkType string) error {
return c.MockConvertDevice(d, networkType)
}
Loading