feat: add cpu-reaper-operator source code

This commit is contained in:
root
2025-12-12 16:33:15 +09:00
parent 59894d6413
commit c3fab1781b
49 changed files with 2450 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// CpuReaperPolicySpec defines the desired state
type CpuReaperPolicySpec struct {
PodSelector *metav1.LabelSelector `json:"podSelector,omitempty"`
ThresholdPercent int `json:"thresholdPercent,omitempty"`
ForSeconds int `json:"forSeconds,omitempty"`
CheckIntervalSeconds int `json:"checkIntervalSeconds,omitempty"`
RequireLimits bool `json:"requireLimits,omitempty"`
}
// CpuReaperPolicyStatus defines the observed state
type CpuReaperPolicyStatus struct {
}
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
type CpuReaperPolicy struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec CpuReaperPolicySpec `json:"spec,omitempty"`
Status CpuReaperPolicyStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
type CpuReaperPolicyList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []CpuReaperPolicy `json:"items"`
}
func init() {
SchemeBuilder.Register(&CpuReaperPolicy{}, &CpuReaperPolicyList{})
}

View File

@@ -0,0 +1,36 @@
/*
Copyright 2025.
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 contains API Schema definitions for the reaper v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=reaper.cpu.limit.check
package v1alpha1
import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)
var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "reaper.cpu.limit.check", Version: "v1alpha1"}
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)

View File

@@ -0,0 +1,120 @@
//go:build !ignore_autogenerated
/*
Copyright 2025.
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.
*/
// Code generated by controller-gen. DO NOT EDIT.
package v1alpha1
import (
"k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CpuReaperPolicy) DeepCopyInto(out *CpuReaperPolicy) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
out.Status = in.Status
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CpuReaperPolicy.
func (in *CpuReaperPolicy) DeepCopy() *CpuReaperPolicy {
if in == nil {
return nil
}
out := new(CpuReaperPolicy)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *CpuReaperPolicy) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CpuReaperPolicyList) DeepCopyInto(out *CpuReaperPolicyList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]CpuReaperPolicy, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CpuReaperPolicyList.
func (in *CpuReaperPolicyList) DeepCopy() *CpuReaperPolicyList {
if in == nil {
return nil
}
out := new(CpuReaperPolicyList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *CpuReaperPolicyList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CpuReaperPolicySpec) DeepCopyInto(out *CpuReaperPolicySpec) {
*out = *in
if in.PodSelector != nil {
in, out := &in.PodSelector, &out.PodSelector
*out = new(v1.LabelSelector)
(*in).DeepCopyInto(*out)
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CpuReaperPolicySpec.
func (in *CpuReaperPolicySpec) DeepCopy() *CpuReaperPolicySpec {
if in == nil {
return nil
}
out := new(CpuReaperPolicySpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CpuReaperPolicyStatus) DeepCopyInto(out *CpuReaperPolicyStatus) {
*out = *in
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CpuReaperPolicyStatus.
func (in *CpuReaperPolicyStatus) DeepCopy() *CpuReaperPolicyStatus {
if in == nil {
return nil
}
out := new(CpuReaperPolicyStatus)
in.DeepCopyInto(out)
return out
}