generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 15
Add PlacementDecision API and CI workflow #33
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
Open
mikeshng
wants to merge
1
commit into
kubernetes-sigs:main
Choose a base branch
from
mikeshng:placementdecision-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,071
−91
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| lint: | ||
| name: Lint | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: go.mod | ||
| cache: false | ||
|
|
||
| - name: Run golangci-lint | ||
| uses: golangci/golangci-lint-action@v6 | ||
| with: | ||
| version: v1.64.5 | ||
| args: --timeout 5m0s | ||
|
|
||
| verify: | ||
| name: Verify | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: go.mod | ||
| cache: false | ||
|
|
||
| - name: Verify | ||
| run: hack/verify-all.sh -v | ||
|
|
||
| test: | ||
| name: Unit Test | ||
| runs-on: ubuntu-latest | ||
| needs: verify | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: go.mod | ||
| cache: false | ||
|
|
||
| - name: Run tests | ||
| run: make test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ linters: | |
| enable: | ||
| - dupl | ||
| - errcheck | ||
| - exportloopref | ||
| - copyloopvar | ||
| - goconst | ||
| - gocyclo | ||
| - gofmt | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /* | ||
| Copyright 2025 The Kubernetes Authors. | ||
|
|
||
| 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 ( | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| // Label keys used for PlacementDecision correlation and discovery. | ||
| const ( | ||
| // DecisionKeyLabel links all slices to the same decision when a decision spans multiple slices. | ||
| // When multiple slices exist for one logical decision, the producer MUST set the same | ||
| // decision-key on all slices. | ||
| DecisionKeyLabel = "multicluster.x-k8s.io/decision-key" | ||
|
|
||
| // DecisionIndexLabel indicates the index position of this slice when order matters. | ||
| // If a scheduler needs to preserve the order of selected clusters and the result spans | ||
| // multiple slices, it should label each PlacementDecision with this label where the | ||
| // value starts at 0 and increments by 1. | ||
| DecisionIndexLabel = "multicluster.x-k8s.io/decision-index" | ||
|
|
||
| // PlacementKeyLabel links a decision to an originating workload when applicable. | ||
| // Producers may set this label on PlacementDecision slices when the decision is workload scoped. | ||
| // Decisions not tied to a workload need not set this label. | ||
| PlacementKeyLabel = "multicluster.x-k8s.io/placement-key" | ||
| ) | ||
|
|
||
| // ClusterDecision references a target ClusterProfile to apply workloads to. | ||
| type ClusterDecision struct { | ||
| // ClusterProfileRef is a reference to the target ClusterProfile. | ||
| // The reference must point to a valid ClusterProfile in the fleet. | ||
| // +required | ||
| ClusterProfileRef corev1.ObjectReference `json:"clusterProfileRef"` | ||
|
|
||
| // Reason is an optional explanation of why this cluster was chosen. | ||
| // This can be useful for debugging and auditing placement decisions. | ||
| // +optional | ||
| Reason string `json:"reason,omitempty"` | ||
| } | ||
|
|
||
| //+genclient | ||
| //+kubebuilder:object:root=true | ||
| //+kubebuilder:resource:scope=Namespaced | ||
|
|
||
| // PlacementDecision publishes the set of clusters chosen by a scheduler at a point in time. | ||
| // It is a data-only resource that acts as the interface between schedulers and consumers. | ||
| // Schedulers write decisions using this format; consumers read from it. | ||
| // | ||
| // Following the EndpointSlice convention, a single scheduling decision can fan out to N | ||
| // PlacementDecision slices, each limited to 100 clusters. To correlate slices, producers | ||
| // MUST set the same multicluster.x-k8s.io/decision-key label on all slices when more than | ||
| // one slice exists. | ||
| type PlacementDecision struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
|
||
| // Decisions is the list of clusters chosen for this placement decision. | ||
| // Up to 100 ClusterDecisions per object (slice) to stay well below the etcd limit. | ||
| // +kubebuilder:validation:MinItems=0 | ||
| // +kubebuilder:validation:MaxItems=100 | ||
| // +required | ||
| Decisions []ClusterDecision `json:"decisions"` | ||
|
|
||
| // SchedulerName is the name of the scheduler that created this decision. | ||
| // This is optional and can be used for debugging and auditing purposes. | ||
| // +optional | ||
| SchedulerName string `json:"schedulerName,omitempty"` | ||
| } | ||
|
|
||
| //+kubebuilder:object:root=true | ||
|
|
||
| // PlacementDecisionList contains a list of PlacementDecision. | ||
| type PlacementDecisionList struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ListMeta `json:"metadata,omitempty"` | ||
| Items []PlacementDecision `json:"items"` | ||
| } | ||
|
|
||
| func init() { | ||
| SchemeBuilder.Register(&PlacementDecision{}, &PlacementDecisionList{}) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, defining reference in this file rather than using objectRef would bring better doc on API