Skip to content

Commit

Permalink
Add core code to support namespace based CRDs
Browse files Browse the repository at this point in the history
Signed-off-by: Billy McFall <[email protected]>
  • Loading branch information
Billy99 committed Dec 4, 2024
1 parent d86dfcd commit f776292
Show file tree
Hide file tree
Showing 93 changed files with 4,378 additions and 401 deletions.
79 changes: 79 additions & 0 deletions apis/v1alpha1/bpfprogram_ns_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Copyright 2024.
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.
*/

// All fields are required unless explicitly marked optional
// +kubebuilder:validation:Required
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1types "k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// BpfNsProgram is the Schema for the Bpfnsprograms API
// +kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.spec.type`
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[0].reason`
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
type BpfNsProgram struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BpfProgramSpec `json:"spec"`
// +optional
Status BpfProgramStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// BpfNsProgramList contains a list of BpfProgram
type BpfNsProgramList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []BpfNsProgram `json:"items"`
}

func (bp BpfNsProgram) GetName() string {
return bp.Name
}

func (bp BpfNsProgram) GetUID() metav1types.UID {
return bp.UID
}

func (bp BpfNsProgram) GetAnnotations() map[string]string {
return bp.Annotations
}

func (bp BpfNsProgram) GetLabels() map[string]string {
return bp.Labels
}

func (bp BpfNsProgram) GetStatus() *BpfProgramStatus {
return &bp.Status
}

func (bp BpfNsProgram) GetClientObject() client.Object {
return &bp
}

func (bpl BpfNsProgramList) GetItems() []BpfNsProgram {
return bpl.Items
}
30 changes: 30 additions & 0 deletions apis/v1alpha1/bpfprogram_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1types "k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// +genclient
Expand Down Expand Up @@ -69,3 +71,31 @@ type BpfProgramList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []BpfProgram `json:"items"`
}

func (bp BpfProgram) GetName() string {
return bp.Name
}

func (bp BpfProgram) GetUID() metav1types.UID {
return bp.UID
}

func (bp BpfProgram) GetAnnotations() map[string]string {
return bp.Annotations
}

func (bp BpfProgram) GetLabels() map[string]string {
return bp.Labels
}

func (bp BpfProgram) GetStatus() *BpfProgramStatus {
return &bp.Status
}

func (bp BpfProgram) GetClientObject() client.Object {
return &bp
}

func (bpl BpfProgramList) GetItems() []BpfProgram {
return bpl.Items
}
52 changes: 52 additions & 0 deletions apis/v1alpha1/xdpProgram_ns_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2024.
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.
*/

// All fields are required unless explicitly marked optional
// +kubebuilder:validation:Required
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Namespaced

// XdpNsProgram is the Schema for the XdpNsPrograms API
// +kubebuilder:printcolumn:name="BpfFunctionName",type=string,JSONPath=`.spec.bpffunctionname`
// +kubebuilder:printcolumn:name="NodeSelector",type=string,JSONPath=`.spec.nodeselector`
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[0].reason`
// +kubebuilder:printcolumn:name="Priority",type=string,JSONPath=`.spec.priority`,priority=1
// +kubebuilder:printcolumn:name="InterfaceSelector",type=string,JSONPath=`.spec.interfaceselector`,priority=1
// +kubebuilder:printcolumn:name="ProceedOn",type=string,JSONPath=`.spec.proceedon`,priority=1
type XdpNsProgram struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec XdpProgramSpec `json:"spec"`
// +optional
Status XdpProgramStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true
// XdpProgramList contains a list of XdpPrograms
type XdpNsProgramList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []XdpNsProgram `json:"items"`
}
118 changes: 118 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

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

4 changes: 4 additions & 0 deletions apis/v1alpha1/zz_generated.register.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@ rules:
- bpfapplications/finalizers
verbs:
- update
- apiGroups:
- bpfman.io
resources:
- bpfnsprograms
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- bpfman.io
resources:
- bpfnsprograms/finalizers
verbs:
- update
- apiGroups:
- bpfman.io
resources:
- bpfnsprograms/status
verbs:
- get
- patch
- update
- apiGroups:
- bpfman.io
resources:
Expand Down Expand Up @@ -142,6 +168,14 @@ rules:
- uprobeprograms/finalizers
verbs:
- update
- apiGroups:
- bpfman.io
resources:
- xdpnsprograms
verbs:
- get
- list
- watch
- apiGroups:
- bpfman.io
resources:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
creationTimestamp: null
name: bpfman-agent-role
rules:
- apiGroups:
- bpfman.io
resources:
- xdpnsprograms
verbs:
- get
- list
- watch
- apiGroups:
- bpfman.io
resources:
- xdpnsprograms/finalizers
verbs:
- update
Loading

0 comments on commit f776292

Please sign in to comment.