Skip to content

Commit

Permalink
Merge pull request #60 from packethost/examples
Browse files Browse the repository at this point in the history
update examples and README for XP 1.2 and EM provider 0.0.7
  • Loading branch information
displague authored Jun 8, 2021
2 parents d24ee2d + 5ae5a4e commit a52bd97
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 47 deletions.
110 changes: 77 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Crossplane Equinix Metal Provider

[![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)
[![crds.dev](https://img.shields.io/badge/Docs-crds.dev-blue)](https://doc.crds.dev/github.com/packethost/crossplane-provider-equinix-metal)
[![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.14/introduction/providers.html):
[From Crossplane's Provider documentation](https://crossplane.io/docs/v1.2/concepts/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.
> 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.
This is the Crossplane Provider package for [Equinix Metal](https://metal.equinix.com)
infrastructure. The provider that is built from this repository can be installed
Expand All @@ -30,66 +31,97 @@ For getting started guides, installation, deployment, and administration, see th

## Installing Crossplane

For the most up to date, detailed, instructions, check [Crossplane's documentation](https://crossplane.io/docs/v0.13/getting-started/install-configure.html).
For the most up to date, detailed, instructions, check [Crossplane's documentation](https://crossplane.io/docs/v1.2/getting-started/install-configure.html#install-crossplane).

The following instructions are provided for convenience.

```console
kubectl create namespace crossplane-system
helm repo add crossplane-alpha https://charts.crossplane.io/alpha
helm install crossplane --namespace crossplane-system crossplane-alpha/crossplane
helm repo add crossplane-stable https://charts.crossplane.io/stable
helm repo update
helm install crossplane --namespace crossplane-system crossplane-stable/crossplane --version 1.2.2
```

### Install the Crossplane CLI

Fetch the CLI and follow the commands provided in the output:

```console
curl -sL https://raw.githubusercontent.com/crossplane/crossplane/release-0.14/install.sh | sh
$ curl -sL https://raw.githubusercontent.com/crossplane/crossplane/master/install.sh | sh
kubectl plugin downloaded successfully! Run the following commands to finish installing it:

sudo mv kubectl-crossplane $HOME/.local/bin
kubectl crossplane --help

Visit https://crossplane.io to get started. 🚀
Have a nice day! 👋
```

```sh
sudo mv kubectl-crossplane $HOME/.local/bin
```

## Install the Equinix Metal Provider

For the most up to date version and install notes, see <https://cloud.upbound.io/registry/equinix/provider-equinix-metal>.

```console
kubectl crossplane install provider equinix/crossplane-provider-equinix-metal
kubectl crossplane install provider registry.upbound.io/equinix/provider-equinix-metal:v0.0.7
```

The following commands will require your [Equinix Metal API key and a project ID](https://metal.equinix.com/developers/docs/). Entering your API key and project ID when prompted:
After the package has been fetched and installed, you should see that the provider package is ready:

```console
read -s -p "API Key: " APIKEY; echo
read -p "Project ID: " PROJECT_ID; echo
kubectl get provider -o wide
NAME INSTALLED HEALTHY PACKAGE AGE
equinix-provider-equinix-metal True True registry.upbound.io/equinix/provider-equinix-metal:v0.0.7 76m
```

### Create a Provider Secret

Create a [Equinix Metal Project and a project level API key](https://metal.equinix.com/developers/docs/).

Create a Kubernetes secret with the API Key and Project ID.
The following commands will require your [Equinix Metal API key and a project ID](https://metal.equinix.com/developers/docs/). Enter your API key and project ID when prompted:

```console
read -s -p "API Key: " APIKEY; echo
read -p "Project ID: " PROJECT_ID; echo
```

_(The `read` command may need to be modified for shells other than bash.)_

Create a Kubernetes secret called `metal-creds` with the API Key and Project ID stored as JSON in a key called `credentials`.

```bash
kubectl create -n crossplane-system secret generic packet-creds --from-file=key=<(echo '{"apiKey":"'$APIKEY'", "projectID":"'$PROJECT_ID'"}')
kubectl create -n crossplane-system secret generic --from-file=credentials=<(echo '{"apiKey":"'$APIKEY'", "projectID":"'$PROJECT_ID'"}') metal-creds
```

### Create a Provider record

Get the project id from the Equinix Metal Portal or using the Equinix Metal CLI (`packet project get`). With `PROJECT_ID` in your environemnt, run the command below:
The secret name and key name are configurable. Whatever names you choose must match the settings in the `ProviderConfig` below.

### Create a Provider Config record

Get the project id from the Equinix Metal Portal or using the Equinix Metal CLI (`packet project get`). With `PROJECT_ID` in your environment, run the command below:

```bash
cat << EOS | kubectl apply -f -
apiVersion: metal.equinix.com/v1beta1
kind: ProviderConfig
metadata:
name: default
name: equinix-metal-provider
spec:
projectID: $PROJECT_ID
credentials:
source: Secret
secretRef:
namespace: crossplane-system
name: packet-creds
key: key
name: metal-creds
key: credentials
EOS
```

_TIP: If the `ProviderConfig` is given the special name "**default**", Equinix Metal Crossplane resources will choose this configuration making the `providerConfigRef` field optional._

## Provision an Equinix Metal Device

Save the following as `device.yaml`:
Expand All @@ -98,47 +130,58 @@ Save the following as `device.yaml`:
apiVersion: server.metal.equinix.com/v1alpha2
kind: Device
metadata:
name: devices
name: crossplane-example
spec:
forProvider:
hostname: crossplane
plan: c1.small.x86
facility: any
operatingSystem: centos_7
hostname: crossplane-example
plan: c3.small.x86
facility: sv15
operatingSystem: ubuntu_20_04
billingCycle: hourly
hardware_reservation_id: next_available
locked: false
networkType: hybrid
tags:
- crossplane
- development
providerConfigRef:
name: equinix-metal-provider
writeConnectionSecretToRef:
name: devices-creds
name: crossplane-example
namespace: crossplane-system
reclaimPolicy: Delete
```
```bash
Create the resource:
```sh
$ kubectl create -f device.yaml
device.server.metal.equinix.com/devices created
secret/devices-creds created
```

To view the device in the cluster:
To view the device and other Equinix Metal resources in the cluster:

```bash
$ kubectl get equinix -o wide
NAME PROJECT-ID AGE SECRET-NAME
provider.metal.equinix.com/packet-provider 0ac84673-b679-40c1-9de9-8a8792675515 38m packet-creds
kubectl get provider
NAME INSTALLED HEALTHY PACKAGE AGE
equinix-provider-equinix-metal True True registry.upbound.io/equinix/provider-equinix-metal:v0.0.7 73m

NAME READY SYNCED STATE ID HOSTNAME FACILITY IPV4 RECLAIM-POLICY AGE
device.server.metal.equinix.com/crossplane-example True True active d81d643a-998f-4203-a667-7f9378481b1d crossplane-example sv15 139.178.68.111 53m

NAME READY SYNCED STATE ID HOSTNAME FACILITY IPV4 RECLAIM-POLICY AGE
device.server.metal.equinix.com/devices True True active 1c73767a-e16a-485c-89b4-4b553e1458b3 crossplane sjc1 139.178.88.35 Delete 19m
NAME AGE CONFIG-NAME RESOURCE-KIND RESOURCE-NAME
providerconfigusage.metal.equinix.com/0a280921-1f3a-48ad-adb2-15ed8e6146f1 53m equinix-metal-provider Device crossplane-example

NAME AGE SECRET-NAME
providerconfig.metal.equinix.com/equinix-metal-provider 69m
```

SSH Connection credentials (including IP address, username, and password) can be found in the provider managed secret defined by `writeConnectionSecretToRef`.

**Caution** - Secret data is Base64 encoded, access to the namespace where this secret is stored offers `root` access to the provisioned device.

```bash
$ kubectl get secret -n crossplane-system devices-creds -o jsonpath='{.data}'; echo
$ kubectl get secret -n crossplane-system crossplane-example -o jsonpath='{.data}'; echo
map[endpoint:MTM5LjE3OC44OC41Nw== password:cGFzc3dvcmQ== port:MjI= username:cm9vdA==]
```

Expand All @@ -147,7 +190,6 @@ To delete the device:
```bash
$ kubectl delete -f device.yaml
device.server.metal.equinix.com/devices deleted
secret/devices-creds deleted
```

## Roadmap and Stability
Expand All @@ -156,6 +198,8 @@ 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).

See <https://github.com/packethost/crossplane-provider-equinix-metal/milestones> for project milestones.

## Contributing

crossplane-provider-equinix-metal is a community driven project and we welcome contributions. See the Crossplane [Contributing](https://github.com/crossplane/crossplane/blob/master/CONTRIBUTING.md) guidelines to get started.
Expand Down
14 changes: 14 additions & 0 deletions cluster/examples/assignment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: ports.metal.equinix.com/v1alpha1
kind: Assignment
metadata:
name: crossplane-example-eth1-xp-vlan
spec:
forProvider:
deviceIdRef:
name: crossplane-example
virtualNetworkIdRef:
name: xp-vlan
name: eth1
providerConfigRef:
name: equinix-metal-provider
22 changes: 14 additions & 8 deletions cluster/examples/device.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
---
apiVersion: server.metal.equinix.com/v1alpha2
kind: Device
metadata:
name: devicea
namespace: app-project1-dev
name: crossplane-example
spec:
forProvider:
hostname: crossplane
plan: c1.small.x86
facility: any
locked: false
operatingSystem: centos_7
hostname: crossplane-example
plan: c3.small.x86
facility: sv15
operatingSystem: ubuntu_20_04
billingCycle: hourly
hardware_reservation_id: next_available
locked: false
networkType: hybrid
tags:
- crossplane
providerConfigRef:
name: equinix-metal-provider
writeConnectionSecretToRef:
name: devicea-conn
name: crossplane-example
namespace: crossplane-system
reclaimPolicy: Delete
4 changes: 2 additions & 2 deletions cluster/examples/provider.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

export BASE64ENCODED_PACKET_PROVIDER_CREDS=$(base64 credentials.txt | tr -d "\n")
sed "s/BASE64ENCODED_PACKET_PROVIDER_CREDS/$BASE64ENCODED_PACKET_PROVIDER_CREDS/g" provider.yaml | kubectl create -f -
export BASE64ENCODED_METAL_PROVIDER_CREDS=$(base64 credentials.txt | tr -d "\n")
sed "s/BASE64ENCODED_METAL_PROVIDER_CREDS/$BASE64ENCODED_METAL_PROVIDER_CREDS/g" provider.yaml | kubectl create -f -
8 changes: 4 additions & 4 deletions cluster/examples/provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ apiVersion: v1
kind: Secret
metadata:
name: example-provider-equinix-metal
namespace: packet-infra-dev
namespace: crossplane-system
type: Opaque
data:
credentials: BASE64ENCODED_PACKET_PROVIDER_CREDS
credentials: BASE64ENCODED_METAL_PROVIDER_CREDS
---
apiVersion: metal.equinix.com/v1beta1
kind: ProviderConfig
metadata:
name: default
name: equinix-metal-provider
spec:
credentialsSecretRef:
name: example-provider-equinix-metal
namespace: packet-infra-dev
namespace: crossplane-system
key: credentials
11 changes: 11 additions & 0 deletions cluster/examples/virtualnetwork.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
apiVersion: vlan.metal.equinix.com/v1alpha1
kind: VirtualNetwork
metadata:
name: xp-vlan
spec:
forProvider:
description: Example Crossplane provisioned VLAN
facility: sv15
providerConfigRef:
name: equinix-metal-provider

0 comments on commit a52bd97

Please sign in to comment.