Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ resources:
- group: mutations
kind: Assign
version: v1alpha1
- group: status
kind: ConnectionPodStatus
version: v1beta1

Copy link
Copy Markdown
Contributor

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?

@nreisch nreisch Jun 17, 2025

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor

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?

- group: connection
kind: Connection
version: v1alpha1
version: "2"
25 changes: 25 additions & 0 deletions apis/addtoscheme_connection_v1alpha1.go
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)
}
67 changes: 67 additions & 0 deletions apis/connection/v1alpha1/connection_types.go
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{})
}
35 changes: 35 additions & 0 deletions apis/connection/v1alpha1/groupversion_info.go
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
)
125 changes: 125 additions & 0 deletions apis/connection/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions apis/status/v1beta1/connectionpodstatus_types.go
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{})
}
Loading
Loading