-
Notifications
You must be signed in to change notification settings - Fork 866
feat: Export Connection CR #3999
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
Merged
JaydipGabani
merged 16 commits into
open-policy-agent:master
from
nreisch:nreisch/auditExportCrdProd
Jun 25, 2025
Merged
Changes from 7 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c8978ca
feat: Export Connection CR
nreisch 323f023
ci
nreisch 2a35c0d
ci
nreisch 974e56d
lint
nreisch 7009b60
lint
nreisch c56e68c
test improvements
nreisch c53dd35
lint
nreisch cc976b9
address comments
nreisch aec54ba
reset active state
nreisch 08dc142
nit comment
nreisch d9ba430
address comments 2
nreisch 7e50f5a
address comments 3
nreisch d5ab2bd
Merge branch 'master' into nreisch/auditExportCrdProd
nreisch 6dbfd17
lint
nreisch eae2886
address comments 4
nreisch de195a3
nit change name
nreisch 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
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,25 @@ | ||
| /* | ||
|
|
||
| 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 apis | ||
|
|
||
| import ( | ||
| "github.com/open-policy-agent/gatekeeper/v3/apis/connection/v1alpha1" | ||
| ) | ||
|
|
||
| func init() { | ||
| // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back | ||
| AddToSchemes = append(AddToSchemes, v1alpha1.AddToScheme) | ||
| } |
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,67 @@ | ||
| /* | ||
|
|
||
| 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 ( | ||
| status "github.com/open-policy-agent/gatekeeper/v3/apis/status/v1beta1" | ||
| "github.com/open-policy-agent/gatekeeper/v3/pkg/mutation/types" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! | ||
| // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. | ||
|
|
||
| // ConnectionSpec defines the desired state of Connection | ||
| type ConnectionSpec struct { | ||
| // +kubebuilder:validation:Required | ||
| // Driver is the name of one of the expected drivers i.e. dapr, disk | ||
| Driver string `json:"driver"` | ||
| // +kubebuilder:validation:Required | ||
| // +kubebuilder:validation:Schemaless | ||
| // +kubebuilder:validation:XPreserveUnknownFields | ||
| Config *types.Anything `json:"config"` | ||
| } | ||
|
|
||
| // ConnectionStatus defines the observed state of Connection | ||
| type ConnectionStatus struct { | ||
| ByPod []status.ConnectionPodStatusStatus `json:"byPod,omitempty"` | ||
| } | ||
|
|
||
| // +kubebuilder:resource:scope=Namespaced | ||
| // +kubebuilder:object:root=true | ||
| // +kubebuilder:subresource:status | ||
| // +kubebuilder:storageversion | ||
| // Connection is the Schema for the connections API | ||
| type Connection struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
|
||
| Spec ConnectionSpec `json:"spec,omitempty"` | ||
| Status ConnectionStatus `json:"status,omitempty"` | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
|
|
||
| // ConnectionList contains a list of Connection | ||
| type ConnectionList struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ListMeta `json:"metadata,omitempty"` | ||
| Items []Connection `json:"items"` | ||
| } | ||
|
|
||
| func init() { | ||
| SchemeBuilder.Register(&Connection{}, &ConnectionList{}) | ||
| } |
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,35 @@ | ||
| /* | ||
|
|
||
| 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 connection v1alpha1 API group | ||
| // +kubebuilder:object:generate=true | ||
| // +groupName=connection.gatekeeper.sh | ||
| 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: "connection.gatekeeper.sh", 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 | ||
| ) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,104 @@ | ||
| /* | ||
|
|
||
| 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 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/types" | ||
| "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
| ) | ||
|
|
||
| // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! | ||
| // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. | ||
|
|
||
| // ConnectionPodStatusStatus defines the observed state of ConnectionPodStatus | ||
| type ConnectionPodStatusStatus struct { | ||
| // ID is the unique identifier for the pod that wrote the status | ||
| ID string `json:"id,omitempty"` | ||
| ConnectionUID types.UID `json:"connectionUID,omitempty"` | ||
| Operations []string `json:"operations,omitempty"` | ||
| ObservedGeneration int64 `json:"observedGeneration,omitempty"` | ||
| // Indicator for alive connection with at least one successful publish | ||
| Active bool `json:"active,omitempty"` | ||
| Errors []*ConnectionError `json:"errors,omitempty"` | ||
| } | ||
|
|
||
| type ConnectionError struct { | ||
| Type connectionErrorType `json:"type"` | ||
| Message string `json:"message"` | ||
| } | ||
|
|
||
| type connectionErrorType string | ||
|
|
||
| const ( | ||
| UpsertConnectionError connectionErrorType = "UpsertConnection" | ||
| PublishError connectionErrorType = "Publish" | ||
| ) | ||
|
|
||
| // +kubebuilder:object:root=true | ||
| // ConnectionPodStatus is the Schema for the connectionpodstatuses API | ||
| type ConnectionPodStatus struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ObjectMeta `json:"metadata,omitempty"` | ||
| // No spec field is defined here, as this is a status-only resource. | ||
| Status ConnectionPodStatusStatus `json:"status,omitempty"` | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
| // ConnectionPodStatusList contains a list of ConnectionPodStatus | ||
| type ConnectionPodStatusList struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ListMeta `json:"metadata,omitempty"` | ||
| Items []ConnectionPodStatus `json:"items"` | ||
| } | ||
|
|
||
| // NewConnectionStatusForPod returns a connection status object | ||
| // that has been initialized with the bare minimum of fields to make it functional | ||
| // with the connection status controller. | ||
| func NewConnectionStatusForPod(pod *corev1.Pod, connectionNamespace, connectionName string, scheme *runtime.Scheme) (*ConnectionPodStatus, error) { | ||
| obj := &ConnectionPodStatus{} | ||
| name, err := KeyForConnection(pod.Name, connectionNamespace, connectionName) | ||
| 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{ | ||
| ConnectionNameLabel: connectionName, | ||
| PodLabel: pod.Name, | ||
| }) | ||
|
|
||
| if err := controllerutil.SetOwnerReference(pod, obj, scheme); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return obj, nil | ||
| } | ||
|
|
||
| // KeyForConnection returns a unique status object name given the Pod ID and a connection object. | ||
| func KeyForConnection(id string, connectionNamespace string, connectionName string) (string, error) { | ||
| return DashPacker(id, connectionNamespace, connectionName) | ||
| } | ||
|
|
||
| func init() { | ||
| SchemeBuilder.Register(&ConnectionPodStatus{}, &ConnectionPodStatusList{}) | ||
| } |
Oops, something went wrong.
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.
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.
Should this be alpha as this is net new status type?
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.
In the following comment, #2598 (comment) it was suggested to go to beta directly, since the pod status resource isn't interfaced with directly by user facing clients, and instead it's only operated on internally, although it still requires backward compatibility with the status.
However, I do think it make sense to start with alpha to be safe and align with the Connection version, changed to alpha.
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.
I am fine either way based on Max's reasoning. @sozercan @ritazh any thoughts on this?