Skip to content

Commit

Permalink
Merge pull request #98 from instana/k8s_sensor
Browse files Browse the repository at this point in the history
K8s sensor
  • Loading branch information
zach-robinson authored Mar 23, 2023
2 parents 60f7fb1 + b71283b commit 248754c
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 7 deletions.
7 changes: 7 additions & 0 deletions api/v1/inline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ type KubernetesSpec struct {
DeploymentSpec KubernetesDeploymentSpec `json:"deployment,omitempty"`
}

type K8sSpec struct {
// +kubebuilder:validation:Optional
DeploymentSpec KubernetesDeploymentSpec `json:"deployment,omitempty"`
// +kubebuilder:validation:Optional
ImageSpec ImageSpec `json:"image,omitempty"`
}

type KubernetesDeploymentSpec struct {
// Specify if separate deployment of the Kubernetes Sensor should be enabled.
Enabled `json:",inline"`
Expand Down
3 changes: 3 additions & 0 deletions api/v1/instanaagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ type InstanaAgentSpec struct {
// +kubebuilder:validation:Optional
KubernetesSpec `json:"kubernetes,omitempty"`

// +kubebuilder:validation:Optional
K8sSensor K8sSpec `json:"k8s_sensor,omitempty"`

// Specifying the PinnedChartVersion allows for 'pinning' the Helm Chart used by the Operator for installing the Agent
// DaemonSet. Normally the Operator will always install and update to the latest Helm Chart version.
// The Operator will check and make sure no 'unsupported' Chart versions can be selected.
Expand Down
18 changes: 18 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

71 changes: 71 additions & 0 deletions bundle/manifests/instana.io_agents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,77 @@ spec:
additionalProperties:
type: string
type: object
k8s_sensor:
properties:
deployment:
properties:
enabled:
type: boolean
pod:
description: Override pod resource requirements for the Kubernetes
Sensor pods.
properties:
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Requests describes the minimum amount of
compute resources required. If Requests is omitted for
a container, it defaults to Limits if that is explicitly
specified, otherwise to an implementation-defined value.
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
replicas:
description: Specify the number of replicas for the Kubernetes
Sensor.
type: integer
type: object
image:
properties:
digest:
description: Digest (a.k.a. Image ID) of the agent container
image. If specified, it has priority over `agent.image.tag`,
which will then be ignored.
type: string
name:
description: Name is the name of the container image of the
Instana agent.
type: string
pullPolicy:
description: PullPolicy specifies when to pull the image container.
type: string
pullSecrets:
description: PullSecrets allows you to override the default
pull secret that is created when `agent.image.name` starts
with "containers.instana.io". Setting `agent.image.pullSecrets`
prevents the creation of the default "containers-instana-io"
secret.
items:
properties:
name:
type: string
type: object
type: array
tag:
description: Tag is the name of the agent container image;
if `agent.image.digest` is specified, this property is ignored.
type: string
type: object
type: object
kubernetes:
description: Allows for installment of the Kubernetes Sensor as separate
pod. Which allows for better tailored resource settings (mainly
Expand Down
71 changes: 71 additions & 0 deletions config/crd/bases/instana.io_agents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,77 @@ spec:
additionalProperties:
type: string
type: object
k8s_sensor:
properties:
deployment:
properties:
enabled:
type: boolean
pod:
description: Override pod resource requirements for the Kubernetes
Sensor pods.
properties:
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Requests describes the minimum amount of
compute resources required. If Requests is omitted for
a container, it defaults to Limits if that is explicitly
specified, otherwise to an implementation-defined value.
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
replicas:
description: Specify the number of replicas for the Kubernetes
Sensor.
type: integer
type: object
image:
properties:
digest:
description: Digest (a.k.a. Image ID) of the agent container
image. If specified, it has priority over `agent.image.tag`,
which will then be ignored.
type: string
name:
description: Name is the name of the container image of the
Instana agent.
type: string
pullPolicy:
description: PullPolicy specifies when to pull the image container.
type: string
pullSecrets:
description: PullSecrets allows you to override the default
pull secret that is created when `agent.image.name` starts
with "containers.instana.io". Setting `agent.image.pullSecrets`
prevents the creation of the default "containers-instana-io"
secret.
items:
properties:
name:
type: string
type: object
type: array
tag:
description: Tag is the name of the agent container image;
if `agent.image.digest` is specified, this property is ignored.
type: string
type: object
type: object
kubernetes:
description: Allows for installment of the Kubernetes Sensor as separate
pod. Which allows for better tailored resource settings (mainly
Expand Down
16 changes: 10 additions & 6 deletions controllers/instanaagent_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ type InstanaAgentReconciler struct {
leaderElector *leaderelection.LeaderElector
}

//+kubebuilder:rbac:groups=agents.instana.io,resources=instanaagent,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=apps,resources=daemonsets,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=core,resources=pods;secrets;configmaps;services;serviceaccounts,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=agents.instana.io,resources=instanaagent/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=agents.instana.io,resources=instanaagent/finalizers,verbs=update
// +kubebuilder:rbac:groups=agents.instana.io,resources=instanaagent,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=apps,resources=daemonsets,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core,resources=pods;secrets;configmaps;services;serviceaccounts,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=agents.instana.io,resources=instanaagent/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=agents.instana.io,resources=instanaagent/finalizers,verbs=update
func (r *InstanaAgentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := r.log.WithValues("namespace", req.Namespace, "name", req.Name)
log.Info("Reconciling Instana Agent")
Expand Down Expand Up @@ -224,7 +224,11 @@ func (r *InstanaAgentReconciler) Reconcile(ctx context.Context, req ctrl.Request
}

// First try to start Leader Election Coordination so to return error if we cannot get it started
if r.leaderElector == nil || !r.leaderElector.IsLeaderElectionScheduled() {
if crdInstance.Spec.K8sSensor.DeploymentSpec.Enabled.Enabled {
if r.leaderElector != nil {
r.leaderElector.CancelLeaderElection()
}
} else if r.leaderElector == nil || !r.leaderElector.IsLeaderElectionScheduled() {
if r.leaderElector != nil {
// As we'll replace the Leader Elector instance make sure to properly clean up old one
r.leaderElector.CancelLeaderElection()
Expand Down
2 changes: 1 addition & 1 deletion controllers/reconciliation/helm/post_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (p *AgentChartPostRenderer) Run(in *bytes.Buffer) (*bytes.Buffer, error) {
p.log.V(1).Info("Removing leader-elector sidecar from DaemonSet was successful")
}

if !(r.ObjectName() == "clusterroles/instana-agent" || r.ObjectName() == "clusterrolebindings/instana-agent") {
if !(r.ObjectName() == "clusterroles/instana-agent" || r.ObjectName() == "clusterrolebindings/instana-agent" || r.ObjectName() == "clusterroles/k8sensor" || r.ObjectName() == "clusterrolebindings/k8sensor") {
if err := controllerutil.SetControllerReference(p.crdInstance, modifiedResource, p.scheme); err != nil {
return err
}
Expand Down

0 comments on commit 248754c

Please sign in to comment.