Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds provisioner limits based on cpu and mem #817

Merged
merged 27 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
632e737
Limit provisioner by cpu and memory
suket22 Nov 19, 2021
db8dbb1
Update pkg/apis/provisioning/v1alpha5/provisioner.go
suket22 Nov 19, 2021
5a7759a
Update pkg/controllers/provisioning/provisioner.go
suket22 Nov 19, 2021
5c5b3cf
Update pkg/controllers/provisioning/resourcecounter.go
suket22 Nov 19, 2021
e00778a
Separate controller for counting resources
suket22 Nov 22, 2021
4a6cd5e
Separate controller for counting resources
suket22 Nov 22, 2021
7633fc9
Etarn fixes
ellistarn Nov 23, 2021
9310ccd
Merge pull request #1 from ellistarn/limitsImpl
suket22 Nov 23, 2021
217942f
Some more fixes - don't default the status
suket22 Nov 23, 2021
2f291aa
Remove extra logging statement
suket22 Nov 23, 2021
9d67667
Fix defaults, fix binding errors
suket22 Nov 23, 2021
3285786
More minor fixes
suket22 Nov 23, 2021
4531d68
Remove extra patch from rbac
suket22 Nov 23, 2021
00a10d2
Addressing comments on the PR
suket22 Nov 23, 2021
2e20056
Compare provisionerSpecs before stopping existing Provisioners
suket22 Nov 23, 2021
7134769
Fix failing build!
suket22 Nov 23, 2021
64c1714
Merge branch 'main' into limitsImpl
suket22 Nov 23, 2021
555d18d
Don't reassign the provisioner in the launcher
suket22 Nov 24, 2021
f866907
Addressing more comments on the PR
suket22 Nov 24, 2021
74d6bd9
Adds basic unit test
suket22 Nov 24, 2021
afa1796
Update pkg/controllers/counter/controller.go
suket22 Nov 24, 2021
9974847
Update pkg/apis/provisioning/v1alpha5/provisioner.go
suket22 Nov 24, 2021
dfbc043
Update pkg/controllers/counter/controller.go
suket22 Nov 24, 2021
3036eea
More refactoring
suket22 Nov 24, 2021
ca36e42
Merge branch 'main' into limitsImpl
suket22 Nov 24, 2021
26c1831
Update pkg/controllers/provisioning/suite_test.go
suket22 Nov 24, 2021
2591f0a
Apply suggestions from code review
suket22 Nov 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Some more fixes - don't default the status
  • Loading branch information
suket22 committed Nov 23, 2021
commit 217942f2c46abd719627846af839a756a54e86d1
1 change: 0 additions & 1 deletion pkg/apis/provisioning/v1alpha5/provisioner_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func (p *Provisioner) SetDefaults(ctx context.Context) {
logging.FromContext(ctx).Info("Calling Defauling webhook w/ status", pretty.Concise(p.Name), pretty.Concise(p.Status))
p.Spec.Constraints.Default(ctx)
p.Spec.Limits.Default(ctx)
// p.Status.Default(ctx)
}

// Default the constraints
Expand Down
9 changes: 0 additions & 9 deletions pkg/apis/provisioning/v1alpha5/provisioner_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ specific language governing permissions and limitations under the License.
package v1alpha5

import (
"context"

v1 "k8s.io/api/core/v1"
"knative.dev/pkg/apis"
)
Expand Down Expand Up @@ -50,10 +48,3 @@ func (p *Provisioner) GetConditions() apis.Conditions {
func (p *Provisioner) SetConditions(conditions apis.Conditions) {
p.Status.Conditions = conditions
}

func (p *ProvisionerStatus) Default(ctx context.Context) {
// p.Resources = v1.ResourceList{
// ResourceLimitsCPU: *resource.NewScaledQuantity(0, 0),
// ResourceLimitsMemory: *resource.NewScaledQuantity(0, 0),
// }
}
23 changes: 6 additions & 17 deletions pkg/controllers/counter/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/awslabs/karpenter/pkg/apis/provisioning/v1alpha5"
"github.com/awslabs/karpenter/pkg/utils/pretty"
)

// Controller for the resource
Expand All @@ -61,7 +60,6 @@ func (c *Controller) Reconcile(ctx context.Context, req reconcile.Request) (reco
if !errors.IsNotFound(err) {
return reconcile.Result{}, err
}
logging.FromContext(ctx).Infof("not found")
return reconcile.Result{}, nil
}
persisted := provisioner.DeepCopy()
Expand All @@ -72,22 +70,11 @@ func (c *Controller) Reconcile(ctx context.Context, req reconcile.Request) (reco
return reconcile.Result{}, err
}

fmt.Printf("Total cpu usage %v and mem %v\n", resourceCounts[v1alpha5.ResourceLimitsCPU], resourceCounts[v1alpha5.ResourceLimitsMemory])

provisioner.Status.Resources = resourceCounts

logging.FromContext(ctx).Info("before", pretty.Concise(provisioner.Status), pretty.Concise(persisted.Status))
// //
// if err := c.kubeClient.Status().Update(ctx, provisioner); err != nil {
// return reconcile.Result{}, fmt.Errorf("updating provisioner %s, %w", provisioner.Name, err)
// }

if err := c.kubeClient.Status().Patch(ctx, provisioner, client.MergeFrom(persisted)); err != nil {
return reconcile.Result{}, fmt.Errorf("failed to persist changes to %s, %w", req.NamespacedName, err)
}

logging.FromContext(ctx).Info("after", pretty.Concise(provisioner.Status))

// Refresh the reconciler state values every 5 minutes irrespective of node events
return reconcile.Result{RequeueAfter: 5 * time.Minute}, nil
suket22 marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down Expand Up @@ -128,11 +115,13 @@ func (c *Controller) Register(ctx context.Context, m manager.Manager) error {
// Reconcile provisioner state when a node managed by it is created or deleted.
suket22 marked this conversation as resolved.
Show resolved Hide resolved
&source.Kind{Type: &v1.Node{}},
handler.EnqueueRequestsFromMapFunc(func(o client.Object) (requests []reconcile.Request) {
suket22 marked this conversation as resolved.
Show resolved Hide resolved
provisionerName := o.GetLabels()[v1alpha5.ProvisionerNameLabelKey]
requests = append(requests, reconcile.Request{NamespacedName: types.NamespacedName{Name: provisionerName}})
return requests
if provisionerName, ok := o.GetLabels()[v1alpha5.ProvisionerNameLabelKey]; ok {
suket22 marked this conversation as resolved.
Show resolved Hide resolved
requests = append(requests, reconcile.Request{NamespacedName: types.NamespacedName{Name: provisionerName}})
suket22 marked this conversation as resolved.
Show resolved Hide resolved
return requests
}
return nil
}),
).
WithOptions(controller.Options{MaxConcurrentReconciles: 1}).
WithOptions(controller.Options{MaxConcurrentReconciles: 10}).
Complete(c)
}