Skip to content

Commit

Permalink
Wired up controller to main and trivial test
Browse files Browse the repository at this point in the history
  • Loading branch information
ellistarn committed Jan 26, 2021
1 parent 1160d1a commit 6f6d1ab
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 34 deletions.
8 changes: 8 additions & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/awslabs/karpenter/pkg/autoscaler"
horizontalautoscalerv1alpha1 "github.com/awslabs/karpenter/pkg/controllers/horizontalautoscaler/v1alpha1"
metricsproducerv1alpha1 "github.com/awslabs/karpenter/pkg/controllers/metricsproducer/v1alpha1"
provisionerv1alpha1 "github.com/awslabs/karpenter/pkg/controllers/provisioner/v1alpha1"
"github.com/awslabs/karpenter/pkg/controllers/provisioner/v1alpha1/allocation"
scalablenodegroupv1alpha1 "github.com/awslabs/karpenter/pkg/controllers/scalablenodegroup/v1alpha1"
metricsclients "github.com/awslabs/karpenter/pkg/metrics/clients"
"github.com/awslabs/karpenter/pkg/metrics/producers"
Expand Down Expand Up @@ -71,6 +73,12 @@ func main() {
&horizontalautoscalerv1alpha1.Controller{AutoscalerFactory: autoscalerFactory},
&scalablenodegroupv1alpha1.Controller{CloudProvider: cloudProviderFactory},
&metricsproducerv1alpha1.Controller{ProducerFactory: metricsProducerFactory},
&provisionerv1alpha1.Controller{
Client: manager.GetClient(),
Allocator: &allocation.GreedyAllocator{
Capacity: cloudProviderFactory.Capacity(),
},
},
).Start(controllerruntime.SetupSignalHandler()); err != nil {
zap.S().Panicf("Unable to start manager, %w", err)
}
Expand Down
49 changes: 17 additions & 32 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,73 +1,58 @@

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: karpenter
rules:
- apiGroups:
- autoscaling.karpenter.sh
resources:
- horizontalautoscalers
- horizontalautoscalers/status
verbs:
- create
- delete
- get
- list
- patch
- watch
- apiGroups:
- autoscaling.karpenter.sh
resources:
- metricsproducers
- metricsproducers/status
- scalablenodegroups
- scalablenodegroups/status
- provisioners
- provisioners/status
verbs:
- create
- delete
- get
- list
- patch
- watch
- apiGroups:
- '*'
resources:
- '*/scale'
verbs:
- update
- get
- list
- patch
- watch
- apiGroups:
- autoscaling.karpenter.sh
- provisioning.karpenter.sh
resources:
- scalablenodegroups
- scalablenodegroups/status
- provisioners
- provisioners/status
verbs:
- create
- delete
- patch
- get
- list
- patch
- watch
- apiGroups:
- autoscaling.karpenter.sh
- coordination.k8s.io
resources:
- scalablenodegroups/scale
- leases
verbs:
- create
- get
- patch
- update
- watch
- apiGroups:
- coordination.k8s.io
- '*'
resources:
- leases
- '*/scale'
verbs:
- create
- get
- patch
- update
- get
- list
- watch
- apiGroups:
- ""
Expand Down
5 changes: 5 additions & 0 deletions docs/examples/provisioner/provisioner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: autoscaling.karpenter.sh/v1alpha1
kind: Provisioner
metadata:
name: example
spec: {}
6 changes: 5 additions & 1 deletion pkg/cloudprovider/aws/capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewCapacity(client ec2iface.EC2API) *Capacity {
}

// Create a set of nodes given the constraints
func (cp *Capacity) Create(context.Context, cloudprovider.CapacityConstraints) error {
func (cp *Capacity) Create(ctx context.Context, constraints cloudprovider.CapacityConstraints) error {
// Convert contraints to the Node types and select the launch template
// TODO

Expand All @@ -43,6 +43,9 @@ func (cp *Capacity) Create(context.Context, cloudprovider.CapacityConstraints) e

// Set AvailabilityZone, subnet, capacity, on-demand or spot
// and validateAndCreate instances
if err := config.validateAndCreate(ctx); err != nil {
return err
}
return nil
}

Expand Down Expand Up @@ -86,5 +89,6 @@ func (cfg *instanceConfig) validateAndCreate(ctx context.Context) error {
}
// TODO Get instanceID from the output
_ = output
_ = cfg.instanceID
return nil
}
1 change: 0 additions & 1 deletion pkg/cloudprovider/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type Factory interface {
NodeGroupFor(sng *v1alpha1.ScalableNodeGroupSpec) NodeGroup
// QueueFor returns a queue for the provided spec
QueueFor(queue *v1alpha1.QueueSpec) Queue

// Capacity returns a provisioner for the provider to create instances
Capacity() Capacity
}
Expand Down
64 changes: 64 additions & 0 deletions pkg/controllers/provisioner/v1alpha1/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"context"
"testing"

"github.com/awslabs/karpenter/pkg/apis/provisioning/v1alpha1"
"github.com/awslabs/karpenter/pkg/test/environment"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
)

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t,
"Provisioner",
[]Reporter{printer.NewlineReporter{}})
}

var env environment.Environment = environment.NewLocal(func(e *environment.Local) {
e.Manager.Register(&Controller{})
})

var _ = BeforeSuite(func() {
Expect(env.Start()).To(Succeed(), "Failed to start environment")
})

var _ = AfterSuite(func() {
Expect(env.Stop()).To(Succeed(), "Failed to stop environment")
})

var _ = Describe("Provisioner", func() {
var ns *environment.Namespace
var p *v1alpha1.Provisioner

BeforeEach(func() {
var err error
ns, err = env.NewNamespace()
Expect(err).NotTo(HaveOccurred())
p = &v1alpha1.Provisioner{}
})

Context("Provisioner", func() {
It("should do something", func() {
Expect(ns.Create(context.TODO(), p)).To(Succeed())
})
})
})

0 comments on commit 6f6d1ab

Please sign in to comment.