Skip to content

Commit

Permalink
Modify create node image references (#12)
Browse files Browse the repository at this point in the history
* Updates to request node pool images

* remove commit print statements
  • Loading branch information
jrosinsk authored May 6, 2020
1 parent 981ee21 commit aa52554
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.12

require (
github.com/gogo/protobuf v1.3.0 // indirect
github.com/oracle/oci-go-sdk v13.0.0+incompatible
github.com/oracle/oci-go-sdk v19.0.0+incompatible
github.com/pkg/errors v0.8.1
github.com/rancher/kontainer-engine v0.0.0-20190711161432-b98bad2201bb
github.com/rancher/rke v0.2.8 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ github.com/oracle/oci-go-sdk v7.1.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukw
github.com/oracle/oci-go-sdk v13.0.0+incompatible h1:ueAty9OrRXfWi+4gyPLKcOpzhf1OSK70mwt36sD/hf8=
github.com/oracle/oci-go-sdk v13.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888=
github.com/oracle/oci-go-sdk v13.1.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888=
github.com/oracle/oci-go-sdk v19.0.0+incompatible h1:UQnOTZBLEtrqNnJ7jQJiaadScBQ7+CF61+OIvWktkoc=
github.com/oracle/oci-go-sdk v19.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888=
github.com/oracle/oci-manager v0.0.0-20181210225140-b3f0fa436c6b h1:6HTjRyMR6s3eUEYvrM1nvQ3gIT0RcWOqMoBhzRuzZRM=
github.com/oracle/oci-manager v0.0.0-20181210225140-b3f0fa436c6b/go.mod h1:mu49MZKiWx61E+enfYwa8SO2eAcdumsr+eLbXCKfxbs=
github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
Expand Down
46 changes: 45 additions & 1 deletion oke/oke_manager_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
type ClusterManagerClient struct {
configuration common.ConfigurationProvider
containerEngineClient containerengine.ContainerEngineClient
computeClient core.ComputeClient
virtualNetworkClient core.VirtualNetworkClient
identityClient identity.IdentityClient
sleepDuration time.Duration
Expand All @@ -71,6 +72,11 @@ func NewClusterManagerClient(configuration common.ConfigurationProvider) (*Clust
logrus.Debugf("create new ContainerEngine client failed with err %v", err)
return nil, err
}
coreComputeClient, err := core.NewComputeClientWithConfigurationProvider(configuration)
if err != nil {
logrus.Debugf("create new Compute client failed with err %v", err)
return nil, err
}
vNetClient, err := core.NewVirtualNetworkClientWithConfigurationProvider(configuration)
if err != nil {
logrus.Debugf("create new VirtualNetwork client failed with err %v", err)
Expand All @@ -84,6 +90,7 @@ func NewClusterManagerClient(configuration common.ConfigurationProvider) (*Clust
c := &ClusterManagerClient{
configuration: configuration,
containerEngineClient: containerClient,
computeClient: coreComputeClient,
virtualNetworkClient: vNetClient,
identityClient: identityClient,
sleepDuration: 5,
Expand Down Expand Up @@ -224,11 +231,19 @@ func (mgr *ClusterManagerClient) CreateNodePool(ctx context.Context, state *Stat

// Create a node pool for the cluster
npReq := containerengine.CreateNodePoolRequest{}
// get Image Id
image, err := getImageID(ctx, mgr.computeClient, state.CompartmentID, state.NodePool.NodeShape, state.NodePool.NodeImageName)
if err != nil {
logrus.Printf("Node ID not found")
npReq.NodeImageName = common.String(state.NodePool.NodeImageName)
} else {
logrus.Printf("Node ID found %v", image.Id)
npReq.NodeSourceDetails = containerengine.NodeSourceViaImageDetails{ImageId: image.Id}
}
npReq.Name = common.String(state.Name + "-1")
npReq.CompartmentId = common.String(state.CompartmentID)
npReq.ClusterId = &state.ClusterID
npReq.KubernetesVersion = &state.KubernetesVersion
npReq.NodeImageName = common.String(state.NodePool.NodeImageName)
npReq.NodeShape = common.String(state.NodePool.NodeShape)
// Node-pool subnet(s) used for node instances in the node pool.
// These subnets should be different from the cluster Kubernetes Service LB subnets.
Expand Down Expand Up @@ -275,6 +290,35 @@ func (mgr *ClusterManagerClient) CreateNodePool(ctx context.Context, state *Stat
return nil
}

func getImageID(ctx context.Context, c core.ComputeClient, compartment, shape, displayName string) (core.Image, error) {
request := core.ListImagesRequest{
CompartmentId: common.String(compartment),
OperatingSystem: common.String("Oracle Linux"),
Shape: common.String(shape),
}
r, err := c.ListImages(ctx, request)

if err != nil {
logrus.Debugf("listing image id's failed with err %v", err)
return core.Image{}, err
}

index := -1
for n, i := range r.Items {
if strings.Compare(displayName, *i.DisplayName) == 0 {
index = n
break
}
}

if index < 0 {
logrus.Debugf("unable to find an image for displayName: %s", displayName)
return core.Image{}, fmt.Errorf("unable to retrieve image %s", displayName)
}

return r.Items[index], err
}

// GetNodePoolByID returns the node pool with the specified Id, or an error.
func (mgr *ClusterManagerClient) GetNodePoolByID(ctx context.Context, nodePoolID string) (containerengine.NodePool, error) {

Expand Down

0 comments on commit aa52554

Please sign in to comment.