Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

OKE-1853: Refactor lookup node id from node.spec.ProviderID #149

Merged
merged 2 commits into from
Sep 21, 2018

Conversation

simonlord
Copy link
Contributor

OKE-1853: Refactor lookup node id from node.spec.ProviderID …
Completely removed cache and vcn/subnet based lookup. Requires nodes have
node.spec.ProviderID set correctly.

deploy.sh now drops enough info to disk for the flexvolume driver binary to
find, auth and use the kube master api server to query for a list of nodes.

DISCUSS: do we need a non rbac manifest now that we're using a service account?:

DISCUSS: should the rbac roles be rolled into the main driver manifest file?

@simonlord simonlord requested review from prydie and owainlewis August 17, 2018 14:45
Copy link
Contributor

@prydie prydie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor nitpicks but otherwise awesome work 👍 . Will be so pleased to see this land 😄

subjects:
- kind: ServiceAccount
name: oci-fvd
namespace: kube-system
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing newline (you probably need to set "files.insertFinalNewline": true in VSCode)

@@ -1,92 +0,0 @@
// Copyright 2017 Oracle and/or its affiliates. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

}
}
if id == "" {
return id, errors.New("Failed to find node's OCID in returned node list")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error string capitalisation

// Attach initiates the attachment of the given OCI volume to the k8s worker
// node.
func (d OCIFlexvolumeDriver) Attach(opts flexvolume.Options, nodeName string) flexvolume.DriverStatus {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n


nodeList, err := k.CoreV1().Nodes().List(metav1.ListOptions{})
if err != nil {
return "", err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.Wrap(err, "listing nodes")

return kubeClient, err
}

// findNodeID returns the OCID for the given nodeName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: trailing full stop 😜

@@ -10,6 +10,7 @@ spec:
labels:
app: oci-flexvolume-driver
spec:
serviceAccountName: oci-fvd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/oci-fvd/oci-flexvolume-driver/

apiVersion: v1
kind: ServiceAccount
metadata:
name: oci-fvd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/oci-fvd/oci-flexvolume-driver/

deploy.sh Outdated
@@ -40,6 +40,10 @@ if [ -f "$CONFIG_FILE" ]; then
cp "$CONFIG_FILE" "$driver_dir/$config_file_name"
fi

echo https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT > $driver_dir/master_url
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this script shared between both the master and worker DaemonSets? If so we'll want to make sure we don't output this stuff in the worker DaemonSet.


// findNodeID returns the OCID for the given nodeName
func findNodeID(k kubernetes.Interface, nodeName string) (string, error) {
var id string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Would declare adjacent to the for loop personally

@prydie prydie requested a review from jhorwit2 August 17, 2018 15:30
@@ -94,15 +109,70 @@ func deriveVolumeOCID(regionKey string, volumeName string) string {
return volumeOCID
}

func constructKubeClient() (*kubernetes.Clientset, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to be able to construct the client from the env for the managed use case. Let's discuss offline on Monday.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using the same patterns as normal kube services to construct clients. So not copying in cluster access to new directories, using kube config files, etc.

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: oci-fvd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use more descriptive names

@@ -94,15 +109,70 @@ func deriveVolumeOCID(regionKey string, volumeName string) string {
return volumeOCID
}

func constructKubeClient() (*kubernetes.Clientset, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using the same patterns as normal kube services to construct clients. So not copying in cluster access to new directories, using kube config files, etc.

func findNodeID(k kubernetes.Interface, nodeName string) (string, error) {
var id string

nodeList, err := k.CoreV1().Nodes().List(metav1.ListOptions{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have the name name why not use a get?

}
for _, node := range nodeList.Items {
if node.Name == nodeName {
id = node.Spec.ProviderID
Copy link
Member

@jhorwit2 jhorwit2 Aug 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we strip the oci prefix that can be on id's here?

@jhorwit2
Copy link
Member

jhorwit2 commented Aug 19, 2018

@simonlord We should avoid trying to do fancy tactics to provide authentication in the driver itself. This ultimately will depend on the users setup. The recommended way in Kubernetes to do this type of authentication is via kubeconfigs; not copying service accounts.

An example of when this pattern breaks down is when the flex volume driver container is used as part of self-hosted deployment where it's a sidecar in the KCM deployment. Since it's a sidecar t'll already have access to the service account of the KCM. That pattern is used today by ODC.

Also, what happens when SA's can be rotated which is a feature under fairly active discussion. The goal of this driver should be to provide a generic solution to authentication just as every core component does which helps support multiple paradigms of setting up k8s.

@jhorwit2
Copy link
Member

Nit: Upgrading client-go doesn't need to be part of this PR.

@@ -31,6 +32,9 @@ spec:
- mountPath: /tmp
name: config
readOnly: true
- mountPath: /tmp2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An aside (to this PR) but do we really want to mount in /tmp vs something else? (above).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

honestly i don't know, i was just following suit

Copy link
Member

@owainlewis owainlewis Sep 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate discussion maybe but these should be written to more sensible locations IMO.

Copy link
Contributor

@prydie prydie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of minor niggles but nice one 👍. Super excited to say good by to the caching / search code 🎉

README.md Outdated
--from-file=kubeconfig=kubeconfig
```

Once the Secret is set and the daemonsets deployed, the kubeconfig file will be placed onto the master nodes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the Secret is set and the DaemonSet is deployed, the kubeconfig file will be placed onto the master nodes.

@@ -17,12 +17,17 @@ package framework
import (
"errors"
"os"

"github.com/oracle/oci-flexvolume-driver/pkg/oci/driver"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import grouping

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I don't understand

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops my bad. Yeah, supper nit picky but we normally group imports like so:

import (
	<stdlib>

	<k8s.io/...>

	<third party>

	<internal>
)

@@ -0,0 +1,30 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the separation of rbac as a separate manifest 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

README.md Outdated

NOTE: If running kube-controller-managers in a container you _must_ ensure that
the plugin directory is mounted into the container.
You'll still need to add the config file as a kubernetes secret.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/secret/Secret/

@simonlord simonlord force-pushed the sl/with-apiserver branch 2 times, most recently from 8f2df6b to 4132852 Compare September 18, 2018 13:02
// GetInstanceByNodeName retrieves the oci.Instance corresponding or
// a SearchError if no instance matching the node name is found.
GetInstanceByNodeName(name string) (*core.Instance, error)
// GetInstance retrieves the oci.Instance for a given ocid.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivial: for a given OCID

@owainlewis
Copy link
Member

Looking good. Some follow on work needed to coordinate changes with consumers of the driver.

Gopkg.toml Outdated
[[constraint]]
name = "gopkg.in/yaml.v2"
branch = "v2"

[[constraint]]
name = "github.com/oracle/oci-go-sdk"
version = "v1.0.0"

[[constraint]]
branch = "release-1.11"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do i need to do anything for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've generally moved from using the release branch to specifying specific versions of kube deps. We should already have pre-approvals of specific 1.11.x versions of apimachinery I believe too 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved for kubernetes-1.11.1

Copy link
Member

@owainlewis owainlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ensure we're following up on this and communicating the changes with consumers of this plugin.

@owainlewis owainlewis self-assigned this Sep 19, 2018
---
apiVersion: v1
kind: ServiceAccount
metadata:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The service account should be above / in the deployment file. Otherwise there is a race condition on the pods being created and the service account being created which will cause failure events for a short period after deployment.

return "", err
}
if n.Spec.ProviderID == "" {
return "", errors.New("failed to find node's OCID in returned node spec")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this error should be something like node is missing provider id so it's clear where it couldn't find the ocid.

path := GetConfigPath()
if _, err := os.Stat(path); !os.IsNotExist(err) {
k, err := constructKubeClient()
return &OCIFlexvolumeDriver{K: k, master: true}, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this should be

if err != nil {
  return nil, err
}

return &OCIFlexvolumeDriver{K: k, master: true}, nil

…esolution

Completely removed cache and vcn/subnet based lookup. Requires nodes have
node.spec.ProviderID set correctly.

deploy.sh now drops enough info to disk for the flexvolume driver binary to
find, auth and use the kube master api server to query for a list of nodes.
@owainlewis owainlewis merged commit 5e34244 into master Sep 21, 2018
@owainlewis owainlewis deleted the sl/with-apiserver branch September 21, 2018 09:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants