Skip to content

Commit

Permalink
Add logic to register pod Info CRD
Browse files Browse the repository at this point in the history
Currently tetragon uses cilium Endoints to get Pod Labels. Pod Info CRD
is a mapping between Pod IPs and Pod metadata therefore, instead of
using cilium endpoints, it can use the pod info CRs, hence removing the
dependency on cilium.

This commit:
- Added flag to skip PodInfo CRD in the operator, tetragon will use
  endpoints in this case.
- Integrated  logic to register the PodInfo CRD with the API server,
  similar to tracing Policies CRD.

Signed-off-by: Prateek Singh <[email protected]>
  • Loading branch information
prateek041 committed Aug 28, 2023
1 parent 0de4662 commit 6df51ad
Show file tree
Hide file tree
Showing 17 changed files with 683 additions and 65 deletions.
2 changes: 1 addition & 1 deletion install/kubernetes/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ rules:
resourceNames:
- tracingpolicies.cilium.io
- tracingpoliciesnamespaced.cilium.io
- tetragonpods.cilium.io
- podinfo.cilium.io
verbs:
- update
- get
Expand Down
2 changes: 1 addition & 1 deletion install/kubernetes/templates/operator_clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rules:
- apiGroups:
- cilium.io
resources:
- tetragonpods
- podinfo
verbs:
- create
- delete
Expand Down
7 changes: 5 additions & 2 deletions operator/crd/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ func RegisterCRDs() {
// Register the CRDs after validating that we are running on a supported
// version of K8s.
if !option.Config.SkipCRDCreation {
if err := client.RegisterCRDs(k8sAPIExtClient); err != nil {
log.WithError(err).Fatal("Unable to register CRDs")
skipPodInfo := option.Config.SkipPodInfoCRD

// if skipPodInfoCRD flag set true, don't register Pod Info CRD.
if err := client.RegisterCRDs(k8sAPIExtClient, skipPodInfo); err != nil {
log.WithError(err).Fatal("Unable to Register CRDs")
}
} else {
log.Info("Skipping creation of CRDs")
Expand Down
5 changes: 4 additions & 1 deletion operator/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ func initializeFlags() {

flags.String(operatorOption.ConfigDir, "", "Directory in which tetragon-operator-config configmap is mounted")

flags.Bool(operatorOption.SkipPodInfoCRD, false, "When true, PodInfo Custom Resource Definition (CRD) will not be created")

viper.BindPFlags(flags)
}

// Populate sets all options with the values from viper.
// configPopulate sets all options with the values from viper.
func configPopulate() {
operatorOption.Config.SkipCRDCreation = viper.GetBool(operatorOption.SkipCRDCreation)
operatorOption.Config.KubeCfgPath = viper.GetString(operatorOption.KubeCfgPath)
operatorOption.Config.ConfigDir = viper.GetString(operatorOption.ConfigDir)
operatorOption.Config.SkipPodInfoCRD = viper.GetBool(operatorOption.SkipPodInfoCRD)
}
7 changes: 7 additions & 0 deletions operator/option/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const (

// ConfigDir specifies the directory in which tetragon-operator-config configmap is mounted.
ConfigDir = "config-dir"

// SkipPodInfoCRD specifies whether the tetragonPod CustomResourceDefinition will be
// disabled
SkipPodInfoCRD = "skip-pod-info-crd"
)

// OperatorConfig is the configuration used by the operator.
Expand All @@ -31,6 +35,9 @@ type OperatorConfig struct {

// ConfigDir specifies the directory in which tetragon-operator-config configmap is mounted.
ConfigDir string

// SkipPodInfoCRD disables creation of the TetragonPod CustomResourceDefinition only.
SkipPodInfoCRD bool
}

// Config represents the operator configuration.
Expand Down
1 change: 1 addition & 0 deletions pkg/k8s/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ generate:
-o . \
--trim-path-prefix github.com/cilium/tetragon/pkg/k8s \
--plural-exceptions TracingPolicyNamespaced:TracingPoliciesNamespaced \
--plural-exceptions PodInfo:PodInfo \

.PHONY: vendor
vendor:
Expand Down
63 changes: 63 additions & 0 deletions pkg/k8s/apis/cilium.io/client/crds/v1alpha1/cilium.io_podinfo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.3
creationTimestamp: null
name: podinfo.cilium.io
spec:
group: cilium.io
names:
kind: PodInfo
listKind: PodInfoList
plural: podinfo
singular: podinfo
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: PodInfo is the Schema for the PodInfo API
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
spec:
properties:
hostNetwork:
description: Host networking requested for this pod. Use the host's
network namespace. If this option is set, the ports that will be
used must be specified.
type: boolean
type: object
status:
properties:
podIP:
description: IP address allocated to the pod. Routable at least within
the cluster. Empty if not yet allocated.
type: string
podIPs:
description: List of Ip addresses allocated to the pod. 0th entry
must be same as PodIP.
items:
properties:
ip:
description: ip is an IP address (IPv4 or IPv6) assigned to
the pod
type: string
type: object
type: array
type: object
type: object
served: true
storage: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.12.1
creationTimestamp: null
name: podinfoes.cilium.io
spec:
group: cilium.io
names:
kind: PodInfo
listKind: PodInfoList
plural: podinfoes
singular: podinfo
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: PodInfo is the Scheme for the Podinfo API
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
spec:
properties:
hostNetwork:
description: Host networking requested for this pod. Use the host's
network namespace. If this option is set, the ports that will be
used must be specified.
type: boolean
type: object
status:
properties:
podIP:
description: IP address allocated to the pod. Routable at least within
the cluster. Empty if not yet allocated.
type: string
podIPs:
description: List of Ip addresses allocated to the pod. 0th entry
must be same as PodIP.
items:
properties:
IP:
description: IP is an IP address (IPv4 or IPv6) assigned to
the pod
type: string
type: object
type: array
type: object
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Loading

0 comments on commit 6df51ad

Please sign in to comment.