-
Notifications
You must be signed in to change notification settings - Fork 777
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Avinash Patnala
committed
Sep 16, 2024
1 parent
6b08713
commit d1016c3
Showing
10 changed files
with
385 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,89 @@ | ||
package v1beta1 | ||
|
||
import ( | ||
"github.com/open-policy-agent/gatekeeper/v3/pkg/operations" | ||
"github.com/open-policy-agent/gatekeeper/v3/pkg/util" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
|
||
// "k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
) | ||
|
||
// ConfigPodStatusStatus defines the observed state of ConfigPodStatus. | ||
|
||
// +kubebuilder:object:generate=true | ||
|
||
type ConfigPodStatusStatus struct { | ||
// Important: Run "make" to regenerate code after modifying this file | ||
ID string `json:"id,omitempty"` | ||
ConfigUID types.UID `json:"configUID,omitempty"` | ||
Operations []string `json:"operations,omitempty"` | ||
ObservedGeneration int64 `json:"observedGeneration,omitempty"` | ||
Errors []*ConfigError `json:"errors,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:generate=true | ||
|
||
type ConfigError struct { | ||
Type string `json:"type,omitempty"` | ||
Message string `json:"message"` | ||
} | ||
|
||
// ConfigPodStatus is the Schema for the configpodstatuses API. | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:resource:scope=Namespaced | ||
|
||
type ConfigPodStatus struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Status ConfigPodStatusStatus `json:"status,omitempty"` | ||
} | ||
|
||
// ConfigPodStatusList contains a list of ConfigPodStatus. | ||
|
||
// +kubebuilder:object:root=true | ||
type ConfigPodStatusList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []ConfigPodStatus `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&ConfigPodStatus{}, &ConfigPodStatusList{}) | ||
} | ||
|
||
// NewConfigStatusForPod returns an config status object | ||
// that has been initialized with the bare minimum of fields to make it functional | ||
// with the config status controller. | ||
func NewConfigStatusForPod(pod *corev1.Pod, configName string, scheme *runtime.Scheme) (*ConfigPodStatus, error) { | ||
obj := &ConfigPodStatus{} | ||
name, err := KeyForConfig(pod.Name, configName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
obj.SetName(name) | ||
obj.SetNamespace(util.GetNamespace()) | ||
obj.Status.ID = pod.Name | ||
obj.Status.Operations = operations.AssignedStringList() | ||
obj.SetLabels(map[string]string{ | ||
ConfigNameLabel: configName, | ||
PodLabel: pod.Name, | ||
}) | ||
|
||
if err := controllerutil.SetOwnerReference(pod, obj, scheme); err != nil { | ||
return nil, err | ||
} | ||
|
||
return obj, nil | ||
} | ||
|
||
// KeyForConfig returns a unique status object name given the Pod ID and | ||
// a config object. | ||
func KeyForConfig(id string, configName string) (string, error) { | ||
return DashPacker(id, configName) | ||
} |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
71 changes: 71 additions & 0 deletions
71
config/crd/bases/status.gatekeeper.sh_configpodstatuses.yaml
This file contains 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,71 @@ | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: v0.14.0 | ||
name: configpodstatuses.status.gatekeeper.sh | ||
spec: | ||
group: status.gatekeeper.sh | ||
names: | ||
kind: ConfigPodStatus | ||
listKind: ConfigPodStatusList | ||
plural: configpodstatuses | ||
singular: configpodstatus | ||
scope: Namespaced | ||
versions: | ||
- name: v1beta1 | ||
schema: | ||
openAPIV3Schema: | ||
properties: | ||
apiVersion: | ||
description: |- | ||
APIVersion defines the versioned schema of this representation of an object. | ||
Servers should convert recognized schemas to the latest internal value, and | ||
may reject unrecognized values. | ||
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources | ||
type: string | ||
kind: | ||
description: |- | ||
Kind is a string value representing the REST resource this object represents. | ||
Servers may infer this from the endpoint the client submits requests to. | ||
Cannot be updated. | ||
In CamelCase. | ||
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds | ||
type: string | ||
metadata: | ||
type: object | ||
status: | ||
properties: | ||
configUID: | ||
description: |- | ||
UID is a type that holds unique ID values, including UUIDs. Because we | ||
don't ONLY use UUIDs, this is an alias to string. Being a type captures | ||
intent and helps make sure that UIDs and names do not get conflated. | ||
type: string | ||
errors: | ||
items: | ||
properties: | ||
message: | ||
type: string | ||
type: | ||
type: string | ||
required: | ||
- message | ||
type: object | ||
type: array | ||
id: | ||
description: 'Important: Run "make" to regenerate code after modifying | ||
this file' | ||
type: string | ||
observedGeneration: | ||
format: int64 | ||
type: integer | ||
operations: | ||
items: | ||
type: string | ||
type: array | ||
type: object | ||
type: object | ||
served: true | ||
storage: true |
This file contains 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
Oops, something went wrong.