Skip to content

Commit

Permalink
interface: Policy scheduling API (Azure#367)
Browse files Browse the repository at this point in the history
policy scheduling api
  • Loading branch information
ryanzhang-oss authored Jun 1, 2023
1 parent 6107234 commit 9731ec4
Show file tree
Hide file tree
Showing 42 changed files with 3,953 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
paths-ignore: [docs/**, "**.md", "**.mdx", "**.png", "**.jpg"]

env:
GO_VERSION: '1.18'
GO_VERSION: '1.20'

jobs:
detect-noop:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:

env:
# Common versions
GO_VERSION: '1.18'
GO_VERSION: '1.20'

jobs:

Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
run:
deadline: 10m
go: '1.18'
go: '1.20'

linters:
disable-all: true
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ CLUSTER_CONFIG := $(abspath test/e2e/kind-config.yaml)
# Binaries
# Note: Need to use abspath so we can invoke these from subdirectories

CONTROLLER_GEN_VER := v0.8.0
CONTROLLER_GEN_VER := v0.11.4
CONTROLLER_GEN_BIN := controller-gen
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER))

STATICCHECK_VER := 2022.1.2
STATICCHECK_VER := 2023.1.2
STATICCHECK_BIN := staticcheck
STATICCHECK := $(abspath $(TOOLS_BIN_DIR)/$(STATICCHECK_BIN)-$(STATICCHECK_VER))

GOIMPORTS_VER := latest
GOIMPORTS_BIN := goimports
GOIMPORTS := $(abspath $(TOOLS_BIN_DIR)/$(GOIMPORTS_BIN)-$(GOIMPORTS_VER))

GOLANGCI_LINT_VER := v1.47.2
GOLANGCI_LINT_VER := v1.52.2
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER))

# ENVTEST_K8S_VERSION refers to the version of k8s binary assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.23.x
ENVTEST_K8S_VERSION = 1.26.x
# ENVTEST_VER is the version of the ENVTEST binary
ENVTEST_VER = latest
ENVTEST_BIN := setup-envtest
Expand Down
102 changes: 102 additions & 0 deletions apis/v1/binding_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
*/

package v1

import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// CRPTrackingLabel is the label that points to the cluster resource policy that creates a resource binding.
const CRPTrackingLabel = labelPrefix + "parentCRP"

// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,categories={fleet},shortName=rb
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:JSONPath=`.status.conditions[?(@.type=="ResourceBindingApplied")].status`,name="Applied",type=string
// +kubebuilder:printcolumn:JSONPath=`.metadata.creationTimestamp`,name="Age",type=date

// ClusterResourceBinding represents a scheduling decision that binds a group of resources to a cluster.
// It must have CRPTrackingLabel that points to the cluster resource policy that creates it.
type ClusterResourceBinding struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// The desired state of ClusterResourceBinding.
// +required
Spec ResourceBindingSpec `json:"spec"`

// The observed status of ClusterResourceBinding.
// +optional
Status ResourceBindingStatus `json:"status,omitempty"`
}

// ResourceBindingSpec defines the desired state of ClusterResourceBinding.
type ResourceBindingSpec struct {
// ResourceSnapshotName is the name of the resource snapshot that this resource binding points to. If the resources are divided into multiple snapshots because of the resource size limit, it will point to the name of the parent snapshot.
ResourceSnapshotName string `json:"resourceSnapshotName"`

// TargetCluster is the name of the cluster that the scheduler assigns the resources to.
TargetCluster string `json:"targetCluster"`
}

// ResourceBindingStatus represents the current status of a ClusterResourceBinding.
type ResourceBindingStatus struct {
// +patchMergeKey=type
// +patchStrategy=merge
// +listType=map
// +listMapKey=type

// Conditions is an array of current observed conditions for ClusterResourceBinding.
// +optional
Conditions []metav1.Condition `json:"conditions"`
}

// ResourceBindingConditionType identifies a specific condition of the ClusterResourceBinding.
type ResourceBindingConditionType string

const (
// ResourceBindingBound indicates the bound condition of the given resources.
// Its condition status can be one of the following:
// - "True" means the corresponding work CR is created in the target cluster's namespace.
// - "False" means the corresponding work CR is not created yet.
// - "Unknown" means it is unknown.
ResourceBindingBound ResourceBindingConditionType = "Bound"

// ResourceBindingApplied indicates the applied condition of the given resources.
// Its condition status can be one of the following:
// - "True" means all the resources are created in the target cluster.
// - "False" means not all the resources are created in the target cluster yet.
// - "Unknown" means it is unknown.
ResourceBindingApplied ResourceBindingConditionType = "Applied"
)

// ClusterResourceBindingList is a collection of ClusterResourceBinding.
// +kubebuilder:resource:scope="Cluster"
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ClusterResourceBindingList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

// items is the list of ClusterResourceBindings.
Items []ClusterResourceBinding `json:"items"`
}

// SetConditions set the given conditions on the ClusterResourceBinding.
func (m *ClusterResourceBinding) SetConditions(conditions ...metav1.Condition) {
for _, c := range conditions {
meta.SetStatusCondition(&m.Status.Conditions, c)
}
}

// GetCondition returns the condition of the given ClusterResourceBinding.
func (m *ClusterResourceBinding) GetCondition(conditionType string) *metav1.Condition {
return meta.FindStatusCondition(m.Status.Conditions, conditionType)
}

func init() {
SchemeBuilder.Register(&ClusterResourceBinding{}, &ClusterResourceBindingList{})
}
Loading

0 comments on commit 9731ec4

Please sign in to comment.