Commit dd4e2468 authored by Maarten de Waard's avatar Maarten de Waard 🤘🏻
Browse files

Merge branch '16-upgrade-to-newer-kubernetes' into 'master'

Resolve "Upgrade to newer Kubernetes"

Closes #16

See merge request !9
parents 5ce31101 2e93d0c3
FROM golang:1.12-alpine as buildenv
FROM golang:1.13-alpine as buildenv
RUN apk add --no-cache git
RUN go get github.com/golang/dep/cmd/dep
RUN mkdir -p /dist/empty
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /dist/dumb-init
RUN chmod 755 /dist/dumb-init
WORKDIR /go/src/ghost
COPY Gopkg.toml ./
COPY go.mod go.sum ./
RUN go mod download
COPY cmd ./cmd
COPY ghost ./ghost
RUN dep ensure
RUN CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o provisioner ./cmd/provisioner
RUN cp /go/src/ghost/provisioner /dist/provisioner
......
[[constraint]]
name = "github.com/golang/glog"
branch = "master"
[[constraint]]
name = "github.com/kubernetes-sigs/sig-storage-lib-external-provisioner"
version = "v2.1.0"
[[constraint]]
name = "k8s.io/api"
version = "kubernetes-1.13.0"
[[constraint]]
name = "k8s.io/apimachinery"
version = "kubernetes-1.13.0"
[[constraint]]
name = "k8s.io/client-go"
version = "10.0.0"
package main
import (
"ghost/ghost"
"greenhost.net/kubernetes-ghost/provisioner/ghost"
"context"
"flag"
"os"
"syscall"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"github.com/golang/glog"
"github.com/kubernetes-sigs/sig-storage-lib-external-provisioner/controller"
"k8s.io/klog"
"sigs.k8s.io/sig-storage-lib-external-provisioner/v6/controller"
)
const (
......@@ -38,12 +38,12 @@ var _ controller.Provisioner = &GreenhostProvisioner{}
func NewGreenhostProvisioner() controller.Provisioner {
cc, err := ghost.NewCosmosClient()
if err != nil {
glog.Fatalf("failed to create CosmosClient: %v", err)
klog.Fatalf("failed to create CosmosClient: %v", err)
}
projectID_, err := cc.GetInstanceData()
project := ""
if err != nil {
glog.Fatalf("failed getting project ID: %s", err)
klog.Fatalf("failed getting project ID: %s", err)
} else {
project = *projectID_
}
......@@ -55,16 +55,16 @@ func NewGreenhostProvisioner() controller.Provisioner {
}
// Provision creates a storage asset and returns a pv object representing it.
func (p *GreenhostProvisioner) Provision(options controller.VolumeOptions) (*v1.PersistentVolume, error) {
func (p *GreenhostProvisioner) Provision(ctx context.Context, options controller.ProvisionOptions) (*v1.PersistentVolume, controller.ProvisioningState, error) {
pvName := options.PVC.ObjectMeta.Name
name := "kubernetes-ghost:" + pvName
region := os.Getenv("GHOST_CLOUD_REGION")
backup := os.Getenv("GHOST_IMAGE_BACKUP")
backupBool := backup == "true"
if (backupBool) {
glog.Info("disk image backups on")
klog.Info("disk image backups on")
} else {
glog.Info("disk image backups off")
klog.Info("disk image backups off")
}
requestedSize := options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]
// Round the requested size up to nearest integer number of gigabytes.
......@@ -79,11 +79,11 @@ func (p *GreenhostProvisioner) Provision(options controller.VolumeOptions) (*v1.
Backup: backupBool,
}
// The Cosmos API returns a description of the created disk image.
glog.Infof("Creating new disk image with specs %v", specs)
klog.Infof("Creating new disk image with specs %v", specs)
diskImage, err := p.cosmosClient.CreateDiskImage(&specs)
if err != nil {
glog.Warningf("Error in creating new disk image %v", err)
return nil, err
klog.Warningf("Error in creating new disk image %v", err)
return nil, controller.ProvisioningFinished, err
}
pv := &v1.PersistentVolume{
......@@ -94,7 +94,7 @@ func (p *GreenhostProvisioner) Provision(options controller.VolumeOptions) (*v1.
},
},
Spec: v1.PersistentVolumeSpec{
PersistentVolumeReclaimPolicy: options.PersistentVolumeReclaimPolicy,
PersistentVolumeReclaimPolicy: *options.StorageClass.ReclaimPolicy,
AccessModes: options.PVC.Spec.AccessModes,
Capacity: v1.ResourceList{
v1.ResourceName(v1.ResourceStorage): requestedSize,
......@@ -112,13 +112,13 @@ func (p *GreenhostProvisioner) Provision(options controller.VolumeOptions) (*v1.
},
}
return pv, nil
return pv, controller.ProvisioningFinished, nil
}
func (p *GreenhostProvisioner) Delete(volume *v1.PersistentVolume) error {
func (p *GreenhostProvisioner) Delete(ctx context.Context, volume *v1.PersistentVolume) error {
pvName := volume.Name
ghostID := volume.Annotations[idAnnotation]
glog.Infof("Deleting pv with name %s and cosmos-id %s", pvName, ghostID)
klog.Infof("Deleting pv with name %s and cosmos-id %s", pvName, ghostID)
p.cosmosClient.DeleteDiskImage(ghostID)
return nil
}
......@@ -129,7 +129,7 @@ func main() {
flag.Parse()
flag.Set("logtostderr", "true")
glog.Info("Starting kubernetes-ghost provisioner.")
klog.Info("Starting kubernetes-ghost provisioner.")
// Do not restrict permissions on created files and directories.
syscall.Umask(0)
......@@ -137,19 +137,19 @@ func main() {
// Create an InClusterConfig.
config, err := rest.InClusterConfig()
if err != nil {
glog.Fatalf("Error creating InClusterConfig: %v", err)
klog.Fatalf("Error creating InClusterConfig: %v", err)
}
// Create a Kubernetes client.
clientSet, err := kubernetes.NewForConfig(config)
if err != nil {
glog.Fatalf("Error creating Kubernetes client: %v", err)
klog.Fatalf("Error creating Kubernetes client: %v", err)
}
// Get the Kubernetes server version.
serverVersion, err := clientSet.Discovery().ServerVersion()
if err != nil {
glog.Fatalf("Error getting Kubernetes server version: %v", err)
klog.Fatalf("Error getting Kubernetes server version: %v", err)
}
// Create the provisioner.
......@@ -164,5 +164,5 @@ func main() {
)
// Run the provision controller.
pc.Run(wait.NeverStop)
pc.Run(context.Background())
}
......@@ -5,7 +5,7 @@ import (
"io/ioutil"
"strings"
"github.com/golang/glog"
"k8s.io/klog"
)
// Read this machine's instance ID and API token as passed on the
......@@ -21,7 +21,7 @@ func getKernelParams() (string, string, error) {
words := strings.Split(strings.TrimRight(string(data), "\x00"), " ")
var instanceID, apiToken string
for _, word := range words {
glog.Infof("cmdline word: %s", word)
klog.Infof("cmdline word: %s", word)
// Split word into parts before and after "=".
components := strings.SplitN(word, "=", 2)
// Check whether this is the argument we're looking for.
......
......@@ -6,7 +6,7 @@ import (
"net/http"
"os"
"github.com/golang/glog"
"k8s.io/klog"
)
type CosmosClient struct {
......@@ -27,7 +27,7 @@ func NewCosmosClient() (*CosmosClient, error) {
func (cc *CosmosClient) ApiCall(method string, endPoint string, data []byte) (*http.Response, error) {
url := os.Getenv("GHOST_COSMOS_API_URL") + endPoint
glog.Infof("calling url: %v", url)
klog.Infof("calling url: %v", url)
// Prepare the body, if present.
var body io.Reader
......@@ -35,7 +35,7 @@ func (cc *CosmosClient) ApiCall(method string, endPoint string, data []byte) (*h
body = nil
} else {
body = bytes.NewReader(data)
glog.Infof("with data: %v", string(data))
klog.Infof("with data: %v", string(data))
}
// Create the HTTP request.
......@@ -50,7 +50,7 @@ func (cc *CosmosClient) ApiCall(method string, endPoint string, data []byte) (*h
// Send the HTTP request.
resp, err := client.Do(req)
if err != nil {
glog.Fatalf("Error in http request: %v", err)
klog.Fatalf("Error in http request: %v", err)
}
return resp, err
......
......@@ -5,7 +5,7 @@ import (
"errors"
"io/ioutil"
"github.com/golang/glog"
"k8s.io/klog"
)
// Specifications of a disk to be created by Cosmos2.
......@@ -46,7 +46,7 @@ func (cc *CosmosClient) CreateDiskImage(specs *Specs) (*DiskImage, error) {
var diskResponse diskResponse
json.NewDecoder(resp.Body).Decode(&diskResponse)
diskImage := diskResponse.DiskImage
glog.Infof("Created DiskImage object: %+v", diskImage)
klog.Infof("Created DiskImage object: %+v", diskImage)
return &diskImage, nil
}
......@@ -65,7 +65,7 @@ func (cc *CosmosClient) detachDiskImage(id string) bool {
resp, err := cc.ApiCall("POST", "/disks/"+id+"/actions", postData)
if err != nil {
glog.Warningf("Error performing API call to Cosmos2: %v", err)
klog.Warningf("Error performing API call to Cosmos2: %v", err)
return false
}
......@@ -74,10 +74,10 @@ func (cc *CosmosClient) detachDiskImage(id string) bool {
} else {
responseData, err := ioutil.ReadAll(resp.Body)
if err != nil {
glog.Warningf("Error reading Cosmos2 response: %v", err)
klog.Warningf("Error reading Cosmos2 response: %v", err)
return false
}
glog.Warningf("Cosmos2 failed to detach disk: %d %s", resp.StatusCode, responseData)
klog.Warningf("Cosmos2 failed to detach disk: %d %s", resp.StatusCode, responseData)
return false
}
}
......@@ -90,7 +90,7 @@ func (cc *CosmosClient) DeleteDiskImage(id string) bool {
resp, err := cc.ApiCall("DELETE", "/disks/"+id, nil)
if err != nil {
glog.Warningf("Error performing API call to Cosmos2: %v", err)
klog.Warningf("Error performing API call to Cosmos2: %v", err)
return false
}
......@@ -99,10 +99,10 @@ func (cc *CosmosClient) DeleteDiskImage(id string) bool {
} else {
responseData, err := ioutil.ReadAll(resp.Body)
if err != nil {
glog.Warningf("Error reading Cosmos2 response: %v", err)
klog.Warningf("Error reading Cosmos2 response: %v", err)
return false
}
glog.Warningf("Cosmos2 failed to delete disk with ID %s returning: %d %s", id, resp.StatusCode, responseData)
klog.Warningf("Cosmos2 failed to delete disk with ID %s returning: %d %s", id, resp.StatusCode, responseData)
return false
}
}
......@@ -144,7 +144,7 @@ func (cc *CosmosClient) GetInstanceData() (*string, error) {
if projectID == nil {
return nil, errors.New("project_id is not set for this instance")
} else {
glog.Infof("Project ID is %s", *projectID)
klog.Infof("Project ID is %s", *projectID)
return projectID, nil
}
}
module greenhost.net/kubernetes-ghost/provisioner
go 1.13
require (
k8s.io/api v0.18.0
k8s.io/apimachinery v0.18.0
k8s.io/client-go v0.18.0
k8s.io/klog v1.0.0
sigs.k8s.io/sig-storage-lib-external-provisioner/v6 v6.0.0
)
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment