this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add api

+744 -7
+10
PROJECT
··· 8 8 - go.kubebuilder.io/v4 9 9 projectName: pist 10 10 repo: github.com/kragniz/pist 11 + resources: 12 + - api: 13 + crdVersion: v1 14 + namespaced: true 15 + controller: true 16 + domain: kgz.sh 17 + group: autoscaling 18 + kind: PrometheusInformedScaleTarget 19 + path: github.com/kragniz/pist/api/v1alpha1 20 + version: v1alpha1 11 21 version: "3"
+36
api/v1alpha1/groupversion_info.go
··· 1 + /* 2 + Copyright 2026. 3 + 4 + Licensed under the Apache License, Version 2.0 (the "License"); 5 + you may not use this file except in compliance with the License. 6 + You may obtain a copy of the License at 7 + 8 + http://www.apache.org/licenses/LICENSE-2.0 9 + 10 + Unless required by applicable law or agreed to in writing, software 11 + distributed under the License is distributed on an "AS IS" BASIS, 12 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 + See the License for the specific language governing permissions and 14 + limitations under the License. 15 + */ 16 + 17 + // Package v1alpha1 contains API Schema definitions for the autoscaling v1alpha1 API group. 18 + // +kubebuilder:object:generate=true 19 + // +groupName=autoscaling.kgz.sh 20 + package v1alpha1 21 + 22 + import ( 23 + "k8s.io/apimachinery/pkg/runtime/schema" 24 + "sigs.k8s.io/controller-runtime/pkg/scheme" 25 + ) 26 + 27 + var ( 28 + // GroupVersion is group version used to register these objects. 29 + GroupVersion = schema.GroupVersion{Group: "autoscaling.kgz.sh", Version: "v1alpha1"} 30 + 31 + // SchemeBuilder is used to add go types to the GroupVersionKind scheme. 32 + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} 33 + 34 + // AddToScheme adds the types in this group-version to the given scheme. 35 + AddToScheme = SchemeBuilder.AddToScheme 36 + )
+75
api/v1alpha1/prometheusinformedscaletarget_types.go
··· 1 + /* 2 + Copyright 2026. 3 + 4 + Licensed under the Apache License, Version 2.0 (the "License"); 5 + you may not use this file except in compliance with the License. 6 + You may obtain a copy of the License at 7 + 8 + http://www.apache.org/licenses/LICENSE-2.0 9 + 10 + Unless required by applicable law or agreed to in writing, software 11 + distributed under the License is distributed on an "AS IS" BASIS, 12 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 + See the License for the specific language governing permissions and 14 + limitations under the License. 15 + */ 16 + 17 + package v1alpha1 18 + 19 + import ( 20 + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 + ) 22 + 23 + // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! 24 + // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. 25 + 26 + // PrometheusInformedScaleTargetSpec defines the desired state of PrometheusInformedScaleTarget 27 + type PrometheusInformedScaleTargetSpec struct { 28 + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster 29 + // Important: Run "make" to regenerate code after modifying this file 30 + // The following markers will use OpenAPI v3 schema to validate the value 31 + // More info: https://book.kubebuilder.io/reference/markers/crd-validation.html 32 + 33 + // foo is an example field of PrometheusInformedScaleTarget. Edit prometheusinformedscaletarget_types.go to remove/update 34 + // +optional 35 + Foo *string `json:"foo,omitempty"` 36 + } 37 + 38 + // PrometheusInformedScaleTargetStatus defines the observed state of PrometheusInformedScaleTarget. 39 + type PrometheusInformedScaleTargetStatus struct { 40 + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster 41 + // Important: Run "make" to regenerate code after modifying this file 42 + } 43 + 44 + // +kubebuilder:object:root=true 45 + // +kubebuilder:subresource:status 46 + 47 + // PrometheusInformedScaleTarget is the Schema for the prometheusinformedscaletargets API 48 + type PrometheusInformedScaleTarget struct { 49 + metav1.TypeMeta `json:",inline"` 50 + 51 + // metadata is a standard object metadata 52 + // +optional 53 + metav1.ObjectMeta `json:"metadata,omitempty,omitzero"` 54 + 55 + // spec defines the desired state of PrometheusInformedScaleTarget 56 + // +required 57 + Spec PrometheusInformedScaleTargetSpec `json:"spec"` 58 + 59 + // status defines the observed state of PrometheusInformedScaleTarget 60 + // +optional 61 + Status PrometheusInformedScaleTargetStatus `json:"status,omitempty,omitzero"` 62 + } 63 + 64 + // +kubebuilder:object:root=true 65 + 66 + // PrometheusInformedScaleTargetList contains a list of PrometheusInformedScaleTarget 67 + type PrometheusInformedScaleTargetList struct { 68 + metav1.TypeMeta `json:",inline"` 69 + metav1.ListMeta `json:"metadata,omitempty"` 70 + Items []PrometheusInformedScaleTarget `json:"items"` 71 + } 72 + 73 + func init() { 74 + SchemeBuilder.Register(&PrometheusInformedScaleTarget{}, &PrometheusInformedScaleTargetList{}) 75 + }
+119
api/v1alpha1/zz_generated.deepcopy.go
··· 1 + //go:build !ignore_autogenerated 2 + 3 + /* 4 + Copyright 2026. 5 + 6 + Licensed under the Apache License, Version 2.0 (the "License"); 7 + you may not use this file except in compliance with the License. 8 + You may obtain a copy of the License at 9 + 10 + http://www.apache.org/licenses/LICENSE-2.0 11 + 12 + Unless required by applicable law or agreed to in writing, software 13 + distributed under the License is distributed on an "AS IS" BASIS, 14 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + See the License for the specific language governing permissions and 16 + limitations under the License. 17 + */ 18 + 19 + // Code generated by controller-gen. DO NOT EDIT. 20 + 21 + package v1alpha1 22 + 23 + import ( 24 + runtime "k8s.io/apimachinery/pkg/runtime" 25 + ) 26 + 27 + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 28 + func (in *PrometheusInformedScaleTarget) DeepCopyInto(out *PrometheusInformedScaleTarget) { 29 + *out = *in 30 + out.TypeMeta = in.TypeMeta 31 + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) 32 + in.Spec.DeepCopyInto(&out.Spec) 33 + out.Status = in.Status 34 + } 35 + 36 + // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusInformedScaleTarget. 37 + func (in *PrometheusInformedScaleTarget) DeepCopy() *PrometheusInformedScaleTarget { 38 + if in == nil { 39 + return nil 40 + } 41 + out := new(PrometheusInformedScaleTarget) 42 + in.DeepCopyInto(out) 43 + return out 44 + } 45 + 46 + // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 47 + func (in *PrometheusInformedScaleTarget) DeepCopyObject() runtime.Object { 48 + if c := in.DeepCopy(); c != nil { 49 + return c 50 + } 51 + return nil 52 + } 53 + 54 + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 55 + func (in *PrometheusInformedScaleTargetList) DeepCopyInto(out *PrometheusInformedScaleTargetList) { 56 + *out = *in 57 + out.TypeMeta = in.TypeMeta 58 + in.ListMeta.DeepCopyInto(&out.ListMeta) 59 + if in.Items != nil { 60 + in, out := &in.Items, &out.Items 61 + *out = make([]PrometheusInformedScaleTarget, len(*in)) 62 + for i := range *in { 63 + (*in)[i].DeepCopyInto(&(*out)[i]) 64 + } 65 + } 66 + } 67 + 68 + // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusInformedScaleTargetList. 69 + func (in *PrometheusInformedScaleTargetList) DeepCopy() *PrometheusInformedScaleTargetList { 70 + if in == nil { 71 + return nil 72 + } 73 + out := new(PrometheusInformedScaleTargetList) 74 + in.DeepCopyInto(out) 75 + return out 76 + } 77 + 78 + // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 79 + func (in *PrometheusInformedScaleTargetList) DeepCopyObject() runtime.Object { 80 + if c := in.DeepCopy(); c != nil { 81 + return c 82 + } 83 + return nil 84 + } 85 + 86 + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 87 + func (in *PrometheusInformedScaleTargetSpec) DeepCopyInto(out *PrometheusInformedScaleTargetSpec) { 88 + *out = *in 89 + if in.Foo != nil { 90 + in, out := &in.Foo, &out.Foo 91 + *out = new(string) 92 + **out = **in 93 + } 94 + } 95 + 96 + // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusInformedScaleTargetSpec. 97 + func (in *PrometheusInformedScaleTargetSpec) DeepCopy() *PrometheusInformedScaleTargetSpec { 98 + if in == nil { 99 + return nil 100 + } 101 + out := new(PrometheusInformedScaleTargetSpec) 102 + in.DeepCopyInto(out) 103 + return out 104 + } 105 + 106 + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 107 + func (in *PrometheusInformedScaleTargetStatus) DeepCopyInto(out *PrometheusInformedScaleTargetStatus) { 108 + *out = *in 109 + } 110 + 111 + // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PrometheusInformedScaleTargetStatus. 112 + func (in *PrometheusInformedScaleTargetStatus) DeepCopy() *PrometheusInformedScaleTargetStatus { 113 + if in == nil { 114 + return nil 115 + } 116 + out := new(PrometheusInformedScaleTargetStatus) 117 + in.DeepCopyInto(out) 118 + return out 119 + }
+11
cmd/main.go
··· 36 36 "sigs.k8s.io/controller-runtime/pkg/metrics/filters" 37 37 metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" 38 38 "sigs.k8s.io/controller-runtime/pkg/webhook" 39 + 40 + autoscalingv1alpha1 "github.com/kragniz/pist/api/v1alpha1" 41 + "github.com/kragniz/pist/internal/controller" 39 42 // +kubebuilder:scaffold:imports 40 43 ) 41 44 ··· 47 50 func init() { 48 51 utilruntime.Must(clientgoscheme.AddToScheme(scheme)) 49 52 53 + utilruntime.Must(autoscalingv1alpha1.AddToScheme(scheme)) 50 54 // +kubebuilder:scaffold:scheme 51 55 } 52 56 ··· 198 202 os.Exit(1) 199 203 } 200 204 205 + if err := (&controller.PrometheusInformedScaleTargetReconciler{ 206 + Client: mgr.GetClient(), 207 + Scheme: mgr.GetScheme(), 208 + }).SetupWithManager(mgr); err != nil { 209 + setupLog.Error(err, "unable to create controller", "controller", "PrometheusInformedScaleTarget") 210 + os.Exit(1) 211 + } 201 212 // +kubebuilder:scaffold:builder 202 213 203 214 if metricsCertWatcher != nil {
+57
config/crd/bases/autoscaling.kgz.sh_prometheusinformedscaletargets.yaml
··· 1 + --- 2 + apiVersion: apiextensions.k8s.io/v1 3 + kind: CustomResourceDefinition 4 + metadata: 5 + annotations: 6 + controller-gen.kubebuilder.io/version: v0.18.0 7 + name: prometheusinformedscaletargets.autoscaling.kgz.sh 8 + spec: 9 + group: autoscaling.kgz.sh 10 + names: 11 + kind: PrometheusInformedScaleTarget 12 + listKind: PrometheusInformedScaleTargetList 13 + plural: prometheusinformedscaletargets 14 + singular: prometheusinformedscaletarget 15 + scope: Namespaced 16 + versions: 17 + - name: v1alpha1 18 + schema: 19 + openAPIV3Schema: 20 + description: PrometheusInformedScaleTarget is the Schema for the prometheusinformedscaletargets 21 + API 22 + properties: 23 + apiVersion: 24 + description: |- 25 + APIVersion defines the versioned schema of this representation of an object. 26 + Servers should convert recognized schemas to the latest internal value, and 27 + may reject unrecognized values. 28 + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources 29 + type: string 30 + kind: 31 + description: |- 32 + Kind is a string value representing the REST resource this object represents. 33 + Servers may infer this from the endpoint the client submits requests to. 34 + Cannot be updated. 35 + In CamelCase. 36 + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 37 + type: string 38 + metadata: 39 + type: object 40 + spec: 41 + description: spec defines the desired state of PrometheusInformedScaleTarget 42 + properties: 43 + foo: 44 + description: foo is an example field of PrometheusInformedScaleTarget. 45 + Edit prometheusinformedscaletarget_types.go to remove/update 46 + type: string 47 + type: object 48 + status: 49 + description: status defines the observed state of PrometheusInformedScaleTarget 50 + type: object 51 + required: 52 + - spec 53 + type: object 54 + served: true 55 + storage: true 56 + subresources: 57 + status: {}
+16
config/crd/kustomization.yaml
··· 1 + # This kustomization.yaml is not intended to be run by itself, 2 + # since it depends on service name and namespace that are out of this kustomize package. 3 + # It should be run by config/default 4 + resources: 5 + - bases/autoscaling.kgz.sh_prometheusinformedscaletargets.yaml 6 + # +kubebuilder:scaffold:crdkustomizeresource 7 + 8 + patches: 9 + # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. 10 + # patches here are for enabling the conversion webhook for each CRD 11 + # +kubebuilder:scaffold:crdkustomizewebhookpatch 12 + 13 + # [WEBHOOK] To enable webhook, uncomment the following section 14 + # the following config is for teaching kustomize how to do kustomization for CRDs. 15 + #configurations: 16 + #- kustomizeconfig.yaml
+19
config/crd/kustomizeconfig.yaml
··· 1 + # This file is for teaching kustomize how to substitute name and namespace reference in CRD 2 + nameReference: 3 + - kind: Service 4 + version: v1 5 + fieldSpecs: 6 + - kind: CustomResourceDefinition 7 + version: v1 8 + group: apiextensions.k8s.io 9 + path: spec/conversion/webhook/clientConfig/service/name 10 + 11 + namespace: 12 + - kind: CustomResourceDefinition 13 + version: v1 14 + group: apiextensions.k8s.io 15 + path: spec/conversion/webhook/clientConfig/service/namespace 16 + create: false 17 + 18 + varReference: 19 + - path: metadata/annotations
+1 -1
config/default/kustomization.yaml
··· 15 15 # someName: someValue 16 16 17 17 resources: 18 - #- ../crd 18 + - ../crd 19 19 - ../rbac 20 20 - ../manager 21 21 # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
+8
config/rbac/kustomization.yaml
··· 18 18 - metrics_auth_role.yaml 19 19 - metrics_auth_role_binding.yaml 20 20 - metrics_reader_role.yaml 21 + # For each CRD, "Admin", "Editor" and "Viewer" roles are scaffolded by 22 + # default, aiding admins in cluster management. Those roles are 23 + # not used by the pist itself. You can comment the following lines 24 + # if you do not want those helpers be installed with your Project. 25 + - prometheusinformedscaletarget_admin_role.yaml 26 + - prometheusinformedscaletarget_editor_role.yaml 27 + - prometheusinformedscaletarget_viewer_role.yaml 28 +
+27
config/rbac/prometheusinformedscaletarget_admin_role.yaml
··· 1 + # This rule is not used by the project pist itself. 2 + # It is provided to allow the cluster admin to help manage permissions for users. 3 + # 4 + # Grants full permissions ('*') over autoscaling.kgz.sh. 5 + # This role is intended for users authorized to modify roles and bindings within the cluster, 6 + # enabling them to delegate specific permissions to other users or groups as needed. 7 + 8 + apiVersion: rbac.authorization.k8s.io/v1 9 + kind: ClusterRole 10 + metadata: 11 + labels: 12 + app.kubernetes.io/name: pist 13 + app.kubernetes.io/managed-by: kustomize 14 + name: prometheusinformedscaletarget-admin-role 15 + rules: 16 + - apiGroups: 17 + - autoscaling.kgz.sh 18 + resources: 19 + - prometheusinformedscaletargets 20 + verbs: 21 + - '*' 22 + - apiGroups: 23 + - autoscaling.kgz.sh 24 + resources: 25 + - prometheusinformedscaletargets/status 26 + verbs: 27 + - get
+33
config/rbac/prometheusinformedscaletarget_editor_role.yaml
··· 1 + # This rule is not used by the project pist itself. 2 + # It is provided to allow the cluster admin to help manage permissions for users. 3 + # 4 + # Grants permissions to create, update, and delete resources within the autoscaling.kgz.sh. 5 + # This role is intended for users who need to manage these resources 6 + # but should not control RBAC or manage permissions for others. 7 + 8 + apiVersion: rbac.authorization.k8s.io/v1 9 + kind: ClusterRole 10 + metadata: 11 + labels: 12 + app.kubernetes.io/name: pist 13 + app.kubernetes.io/managed-by: kustomize 14 + name: prometheusinformedscaletarget-editor-role 15 + rules: 16 + - apiGroups: 17 + - autoscaling.kgz.sh 18 + resources: 19 + - prometheusinformedscaletargets 20 + verbs: 21 + - create 22 + - delete 23 + - get 24 + - list 25 + - patch 26 + - update 27 + - watch 28 + - apiGroups: 29 + - autoscaling.kgz.sh 30 + resources: 31 + - prometheusinformedscaletargets/status 32 + verbs: 33 + - get
+29
config/rbac/prometheusinformedscaletarget_viewer_role.yaml
··· 1 + # This rule is not used by the project pist itself. 2 + # It is provided to allow the cluster admin to help manage permissions for users. 3 + # 4 + # Grants read-only access to autoscaling.kgz.sh resources. 5 + # This role is intended for users who need visibility into these resources 6 + # without permissions to modify them. It is ideal for monitoring purposes and limited-access viewing. 7 + 8 + apiVersion: rbac.authorization.k8s.io/v1 9 + kind: ClusterRole 10 + metadata: 11 + labels: 12 + app.kubernetes.io/name: pist 13 + app.kubernetes.io/managed-by: kustomize 14 + name: prometheusinformedscaletarget-viewer-role 15 + rules: 16 + - apiGroups: 17 + - autoscaling.kgz.sh 18 + resources: 19 + - prometheusinformedscaletargets 20 + verbs: 21 + - get 22 + - list 23 + - watch 24 + - apiGroups: 25 + - autoscaling.kgz.sh 26 + resources: 27 + - prometheusinformedscaletargets/status 28 + verbs: 29 + - get
+27 -6
config/rbac/role.yaml
··· 1 + --- 1 2 apiVersion: rbac.authorization.k8s.io/v1 2 3 kind: ClusterRole 3 4 metadata: 4 - labels: 5 - app.kubernetes.io/name: pist 6 - app.kubernetes.io/managed-by: kustomize 7 5 name: manager-role 8 6 rules: 9 - - apiGroups: [""] 10 - resources: ["pods"] 11 - verbs: ["get", "list", "watch"] 7 + - apiGroups: 8 + - autoscaling.kgz.sh 9 + resources: 10 + - prometheusinformedscaletargets 11 + verbs: 12 + - create 13 + - delete 14 + - get 15 + - list 16 + - patch 17 + - update 18 + - watch 19 + - apiGroups: 20 + - autoscaling.kgz.sh 21 + resources: 22 + - prometheusinformedscaletargets/finalizers 23 + verbs: 24 + - update 25 + - apiGroups: 26 + - autoscaling.kgz.sh 27 + resources: 28 + - prometheusinformedscaletargets/status 29 + verbs: 30 + - get 31 + - patch 32 + - update
+9
config/samples/autoscaling_v1alpha1_prometheusinformedscaletarget.yaml
··· 1 + apiVersion: autoscaling.kgz.sh/v1alpha1 2 + kind: PrometheusInformedScaleTarget 3 + metadata: 4 + labels: 5 + app.kubernetes.io/name: pist 6 + app.kubernetes.io/managed-by: kustomize 7 + name: prometheusinformedscaletarget-sample 8 + spec: 9 + # TODO(user): Add fields here
+4
config/samples/kustomization.yaml
··· 1 + ## Append samples of your project ## 2 + resources: 3 + - autoscaling_v1alpha1_prometheusinformedscaletarget.yaml 4 + # +kubebuilder:scaffold:manifestskustomizesamples
+63
internal/controller/prometheusinformedscaletarget_controller.go
··· 1 + /* 2 + Copyright 2026. 3 + 4 + Licensed under the Apache License, Version 2.0 (the "License"); 5 + you may not use this file except in compliance with the License. 6 + You may obtain a copy of the License at 7 + 8 + http://www.apache.org/licenses/LICENSE-2.0 9 + 10 + Unless required by applicable law or agreed to in writing, software 11 + distributed under the License is distributed on an "AS IS" BASIS, 12 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 + See the License for the specific language governing permissions and 14 + limitations under the License. 15 + */ 16 + 17 + package controller 18 + 19 + import ( 20 + "context" 21 + 22 + "k8s.io/apimachinery/pkg/runtime" 23 + ctrl "sigs.k8s.io/controller-runtime" 24 + "sigs.k8s.io/controller-runtime/pkg/client" 25 + logf "sigs.k8s.io/controller-runtime/pkg/log" 26 + 27 + autoscalingv1alpha1 "github.com/kragniz/pist/api/v1alpha1" 28 + ) 29 + 30 + // PrometheusInformedScaleTargetReconciler reconciles a PrometheusInformedScaleTarget object 31 + type PrometheusInformedScaleTargetReconciler struct { 32 + client.Client 33 + Scheme *runtime.Scheme 34 + } 35 + 36 + // +kubebuilder:rbac:groups=autoscaling.kgz.sh,resources=prometheusinformedscaletargets,verbs=get;list;watch;create;update;patch;delete 37 + // +kubebuilder:rbac:groups=autoscaling.kgz.sh,resources=prometheusinformedscaletargets/status,verbs=get;update;patch 38 + // +kubebuilder:rbac:groups=autoscaling.kgz.sh,resources=prometheusinformedscaletargets/finalizers,verbs=update 39 + 40 + // Reconcile is part of the main kubernetes reconciliation loop which aims to 41 + // move the current state of the cluster closer to the desired state. 42 + // TODO(user): Modify the Reconcile function to compare the state specified by 43 + // the PrometheusInformedScaleTarget object against the actual cluster state, and then 44 + // perform operations to make the cluster state reflect the state specified by 45 + // the user. 46 + // 47 + // For more details, check Reconcile and its Result here: 48 + // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.21.0/pkg/reconcile 49 + func (r *PrometheusInformedScaleTargetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { 50 + _ = logf.FromContext(ctx) 51 + 52 + // TODO(user): your logic here 53 + 54 + return ctrl.Result{}, nil 55 + } 56 + 57 + // SetupWithManager sets up the controller with the Manager. 58 + func (r *PrometheusInformedScaleTargetReconciler) SetupWithManager(mgr ctrl.Manager) error { 59 + return ctrl.NewControllerManagedBy(mgr). 60 + For(&autoscalingv1alpha1.PrometheusInformedScaleTarget{}). 61 + Named("prometheusinformedscaletarget"). 62 + Complete(r) 63 + }
+84
internal/controller/prometheusinformedscaletarget_controller_test.go
··· 1 + /* 2 + Copyright 2026. 3 + 4 + Licensed under the Apache License, Version 2.0 (the "License"); 5 + you may not use this file except in compliance with the License. 6 + You may obtain a copy of the License at 7 + 8 + http://www.apache.org/licenses/LICENSE-2.0 9 + 10 + Unless required by applicable law or agreed to in writing, software 11 + distributed under the License is distributed on an "AS IS" BASIS, 12 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 + See the License for the specific language governing permissions and 14 + limitations under the License. 15 + */ 16 + 17 + package controller 18 + 19 + import ( 20 + "context" 21 + 22 + . "github.com/onsi/ginkgo/v2" 23 + . "github.com/onsi/gomega" 24 + "k8s.io/apimachinery/pkg/api/errors" 25 + "k8s.io/apimachinery/pkg/types" 26 + "sigs.k8s.io/controller-runtime/pkg/reconcile" 27 + 28 + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 29 + 30 + autoscalingv1alpha1 "github.com/kragniz/pist/api/v1alpha1" 31 + ) 32 + 33 + var _ = Describe("PrometheusInformedScaleTarget Controller", func() { 34 + Context("When reconciling a resource", func() { 35 + const resourceName = "test-resource" 36 + 37 + ctx := context.Background() 38 + 39 + typeNamespacedName := types.NamespacedName{ 40 + Name: resourceName, 41 + Namespace: "default", // TODO(user):Modify as needed 42 + } 43 + prometheusinformedscaletarget := &autoscalingv1alpha1.PrometheusInformedScaleTarget{} 44 + 45 + BeforeEach(func() { 46 + By("creating the custom resource for the Kind PrometheusInformedScaleTarget") 47 + err := k8sClient.Get(ctx, typeNamespacedName, prometheusinformedscaletarget) 48 + if err != nil && errors.IsNotFound(err) { 49 + resource := &autoscalingv1alpha1.PrometheusInformedScaleTarget{ 50 + ObjectMeta: metav1.ObjectMeta{ 51 + Name: resourceName, 52 + Namespace: "default", 53 + }, 54 + // TODO(user): Specify other spec details if needed. 55 + } 56 + Expect(k8sClient.Create(ctx, resource)).To(Succeed()) 57 + } 58 + }) 59 + 60 + AfterEach(func() { 61 + // TODO(user): Cleanup logic after each test, like removing the resource instance. 62 + resource := &autoscalingv1alpha1.PrometheusInformedScaleTarget{} 63 + err := k8sClient.Get(ctx, typeNamespacedName, resource) 64 + Expect(err).NotTo(HaveOccurred()) 65 + 66 + By("Cleanup the specific resource instance PrometheusInformedScaleTarget") 67 + Expect(k8sClient.Delete(ctx, resource)).To(Succeed()) 68 + }) 69 + It("should successfully reconcile the resource", func() { 70 + By("Reconciling the created resource") 71 + controllerReconciler := &PrometheusInformedScaleTargetReconciler{ 72 + Client: k8sClient, 73 + Scheme: k8sClient.Scheme(), 74 + } 75 + 76 + _, err := controllerReconciler.Reconcile(ctx, reconcile.Request{ 77 + NamespacedName: typeNamespacedName, 78 + }) 79 + Expect(err).NotTo(HaveOccurred()) 80 + // TODO(user): Add more specific assertions depending on your controller's reconciliation logic. 81 + // Example: If you expect a certain status condition after reconciliation, verify it here. 82 + }) 83 + }) 84 + })
+116
internal/controller/suite_test.go
··· 1 + /* 2 + Copyright 2026. 3 + 4 + Licensed under the Apache License, Version 2.0 (the "License"); 5 + you may not use this file except in compliance with the License. 6 + You may obtain a copy of the License at 7 + 8 + http://www.apache.org/licenses/LICENSE-2.0 9 + 10 + Unless required by applicable law or agreed to in writing, software 11 + distributed under the License is distributed on an "AS IS" BASIS, 12 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 + See the License for the specific language governing permissions and 14 + limitations under the License. 15 + */ 16 + 17 + package controller 18 + 19 + import ( 20 + "context" 21 + "os" 22 + "path/filepath" 23 + "testing" 24 + 25 + . "github.com/onsi/ginkgo/v2" 26 + . "github.com/onsi/gomega" 27 + 28 + "k8s.io/client-go/kubernetes/scheme" 29 + "k8s.io/client-go/rest" 30 + "sigs.k8s.io/controller-runtime/pkg/client" 31 + "sigs.k8s.io/controller-runtime/pkg/envtest" 32 + logf "sigs.k8s.io/controller-runtime/pkg/log" 33 + "sigs.k8s.io/controller-runtime/pkg/log/zap" 34 + 35 + autoscalingv1alpha1 "github.com/kragniz/pist/api/v1alpha1" 36 + // +kubebuilder:scaffold:imports 37 + ) 38 + 39 + // These tests use Ginkgo (BDD-style Go testing framework). Refer to 40 + // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. 41 + 42 + var ( 43 + ctx context.Context 44 + cancel context.CancelFunc 45 + testEnv *envtest.Environment 46 + cfg *rest.Config 47 + k8sClient client.Client 48 + ) 49 + 50 + func TestControllers(t *testing.T) { 51 + RegisterFailHandler(Fail) 52 + 53 + RunSpecs(t, "Controller Suite") 54 + } 55 + 56 + var _ = BeforeSuite(func() { 57 + logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) 58 + 59 + ctx, cancel = context.WithCancel(context.TODO()) 60 + 61 + var err error 62 + err = autoscalingv1alpha1.AddToScheme(scheme.Scheme) 63 + Expect(err).NotTo(HaveOccurred()) 64 + 65 + // +kubebuilder:scaffold:scheme 66 + 67 + By("bootstrapping test environment") 68 + testEnv = &envtest.Environment{ 69 + CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, 70 + ErrorIfCRDPathMissing: true, 71 + } 72 + 73 + // Retrieve the first found binary directory to allow running tests from IDEs 74 + if getFirstFoundEnvTestBinaryDir() != "" { 75 + testEnv.BinaryAssetsDirectory = getFirstFoundEnvTestBinaryDir() 76 + } 77 + 78 + // cfg is defined in this file globally. 79 + cfg, err = testEnv.Start() 80 + Expect(err).NotTo(HaveOccurred()) 81 + Expect(cfg).NotTo(BeNil()) 82 + 83 + k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) 84 + Expect(err).NotTo(HaveOccurred()) 85 + Expect(k8sClient).NotTo(BeNil()) 86 + }) 87 + 88 + var _ = AfterSuite(func() { 89 + By("tearing down the test environment") 90 + cancel() 91 + err := testEnv.Stop() 92 + Expect(err).NotTo(HaveOccurred()) 93 + }) 94 + 95 + // getFirstFoundEnvTestBinaryDir locates the first binary in the specified path. 96 + // ENVTEST-based tests depend on specific binaries, usually located in paths set by 97 + // controller-runtime. When running tests directly (e.g., via an IDE) without using 98 + // Makefile targets, the 'BinaryAssetsDirectory' must be explicitly configured. 99 + // 100 + // This function streamlines the process by finding the required binaries, similar to 101 + // setting the 'KUBEBUILDER_ASSETS' environment variable. To ensure the binaries are 102 + // properly set up, run 'make setup-envtest' beforehand. 103 + func getFirstFoundEnvTestBinaryDir() string { 104 + basePath := filepath.Join("..", "..", "bin", "k8s") 105 + entries, err := os.ReadDir(basePath) 106 + if err != nil { 107 + logf.Log.Error(err, "Failed to read directory", "path", basePath) 108 + return "" 109 + } 110 + for _, entry := range entries { 111 + if entry.IsDir() { 112 + return filepath.Join(basePath, entry.Name()) 113 + } 114 + } 115 + return "" 116 + }