Skip to content

Commit

Permalink
Remove instrumentedApplication from Odiglet and Instrumentor, add mig…
Browse files Browse the repository at this point in the history
…ration deletion (#2134)
  • Loading branch information
RonFed authored Jan 6, 2025
1 parent 4e0d84c commit 75b6e80
Show file tree
Hide file tree
Showing 33 changed files with 236 additions and 473 deletions.
4 changes: 0 additions & 4 deletions api/config/crd/bases/odigos.io_instrumentationconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ spec:
- optionKey
type: object
type: array
runtimeDetailsInvalidated:
description: true when the runtime details are invalidated and should
be recalculated
type: boolean
sdkConfigs:
description: |-
Configuration for the OpenTelemetry SDKs that this workload should use.
Expand Down

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

3 changes: 0 additions & 3 deletions api/odigos/v1alpha1/instrumentationconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ type InstrumentationConfigSpec struct {
// the service.name property is used to populate the `service.name` resource attribute in the telemetry generated by this workload
ServiceName string `json:"serviceName,omitempty"`

// true when the runtime details are invalidated and should be recalculated
RuntimeDetailsInvalidated bool `json:"runtimeDetailsInvalidated,omitempty"`

// config for this workload.
// the config is a list to allow for multiple config options and values to be applied.
// the list is processed in order, and the first matching config is applied.
Expand Down
7 changes: 2 additions & 5 deletions cli/cmd/resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ In this doc, we'll keep track of the permissions requested across different reso
| Odiglet | "" | nodes | get, list, watch | Needed for virtual device registration. |
| Odiglet | apps | deployments, daemonsets, statefulsets | get, list, watch | Needed for language detection (temporary until new detection logic is ready). |
| Odiglet | apps | deployments/status, daemonsets/status, statefulsets/status | get | Needed for language detection (temporary until new detection logic is ready). |
| Odiglet | apps | replicasets | get | Needed for language detection (temporary until new detection logic is ready). |
| Odiglet | odigos.io | instrumentedapplications | get, list, watch, create, patch, update | Stores runtime details and language detection (temporary until migration to configs). |
| Odiglet | odigos.io | instrumentedapplications/status | get, patch, update | Updates status of instrumented applications. |
| Odiglet | apps | replicasets | get | Needed for language detection (temporary until new detection logic is ready). | |
| Odiglet | odigos.io | instrumentationinstances | create, get, list, patch, update, watch, delete | Manages instrumentation instances for process state storage. |
| Odiglet | odigos.io | instrumentationinstances/status | get, patch, update | Updates status of instrumentation instances. |
| Odiglet | odigos.io | instrumentationconfigs | get, list, watch, patch, update | Manages instrumentation configurations (future update for runtime details storage). |
| Odiglet | odigos.io | instrumentationconfigs/status | get, patch, update | Updates status of instrumentation configurations. |
| Odiglet | policy | podsecuritypolicies | use | Allows using privileged PSP (if enabled). |
| Instrumentor | "" | nodes, namespaces | get, list, watch | Tracks runtime detection and resource labels for instrumentation. |
| Instrumentor | apps | daemonsets, deployments, statefulsets | get, list, watch, update, patch | Adjusts pod specifications for instrumentation. |
| Instrumentor | odigos.io | instrumentedapplications | delete, get, list, watch | Reacts to runtime detections in workloads. |
| Instrumentor | odigos.io | instrumentedapplications/status | get, patch, update | Updates application statuses post-injection. |
| Instrumentor | odigos.io | instrumentedapplications | delete, get, list, watch | Delete deprecated CR. | |
| Instrumentor | odigos.io | instrumentationconfigs | create, delete, get, list, patch, update, watch | Manages instrumentation configurations. |
| Scheduler | odigos.io | instrumentationconfigs | get, list, watch | Monitors changes in instrumentation configurations for scheduling updates. |
| Autoscaler | odigos.io | instrumentationconfigs | get, list, watch | Reads instrumentation configurations to populate the `data-collector` configmaps. |
Expand Down
12 changes: 0 additions & 12 deletions cli/cmd/resources/odiglet.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,6 @@ func NewOdigletClusterRole(psp bool) *rbacv1.ClusterRole {
Resources: []string{"nodes"},
Verbs: []string{"get", "list", "watch"},
},
{ // Needed for storage of runtime details / language detection (almost deprecated)
// TODO: remove this once Tamir/PR is read for instrumentation app ---> instrumentation config migration
APIGroups: []string{"odigos.io"},
Resources: []string{"instrumentedapplications"},
Verbs: []string{"get", "list", "watch", "create", "patch", "update"},
},
{ // Needed for storage of runtime details / language detection (almost deprecated)
// TODO: remove this once Tamir/PR is read for instrumentation app ---> instrumentation config migration
APIGroups: []string{"odigos.io"},
Resources: []string{"instrumentedapplications/status"},
Verbs: []string{"get", "patch", "update"},
},
{ // Needed for storage of the process instrumentation state
APIGroups: []string{"odigos.io"},
Resources: []string{"instrumentationinstances"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ spec:
- optionKey
type: object
type: array
runtimeDetailsInvalidated:
description: true when the runtime details are invalidated and should
be recalculated
type: boolean
sdkConfigs:
description: |-
Configuration for the OpenTelemetry SDKs that this workload should use.
Expand Down
19 changes: 0 additions & 19 deletions helm/odigos/templates/odiglet/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,6 @@ rules:
- get
- list
- watch
- apiGroups:
- odigos.io
resources:
- instrumentedapplications
verbs:
- get
- list
- watch
- create
- patch
- update
- apiGroups:
- odigos.io
resources:
- instrumentedapplications/status
verbs:
- get
- patch
- update
- apiGroups:
- odigos.io
resources:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package deleteinstrumentedapplication
package deleteinstrumentationconfig

import (
"context"
Expand All @@ -24,7 +24,7 @@ func reconcileWorkloadObject(ctx context.Context, kubeClient client.Client, work
return nil
}

if err := deleteWorkloadInstrumentedApplication(ctx, kubeClient, workloadObject); err != nil {
if err := deleteWorkloadInstrumentationConfig(ctx, kubeClient, workloadObject); err != nil {
logger.Error(err, "error removing runtime details")
return err
}
Expand All @@ -37,29 +37,18 @@ func reconcileWorkloadObject(ctx context.Context, kubeClient client.Client, work
return nil
}

func deleteWorkloadInstrumentedApplication(ctx context.Context, kubeClient client.Client, workloadObject client.Object) error {

func deleteWorkloadInstrumentationConfig(ctx context.Context, kubeClient client.Client, workloadObject client.Object) error {
ns := workloadObject.GetNamespace()
name := workloadObject.GetName()
kind := workload.WorkloadKindFromClientObject(workloadObject)
instrumentedApplicationName := workload.CalculateWorkloadRuntimeObjectName(name, kind)

instAppErr := kubeClient.Delete(ctx, &odigosv1.InstrumentedApplication{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: instrumentedApplicationName,
},
})

instConfigErr := kubeClient.Delete(ctx, &odigosv1.InstrumentationConfig{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: instrumentedApplicationName,
},
})
if instAppErr != nil {
return client.IgnoreNotFound(instAppErr)
}

if instConfigErr != nil {
return client.IgnoreNotFound(instConfigErr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package deleteinstrumentedapplication
package deleteinstrumentationconfig

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package deleteinstrumentedapplication
package deleteinstrumentationconfig

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package deleteinstrumentedapplication_test
package deleteinstrumentationconfig_test

import (
"context"
Expand All @@ -11,13 +11,13 @@ import (
corev1 "k8s.io/api/core/v1"
)

var _ = Describe("deleteInstrumentedApplication Deployment controller", func() {
var _ = Describe("deleteInstrumentationConfig Deployment controller", func() {
ctx := context.Background()
var namespace *corev1.Namespace
var deployment *appsv1.Deployment
var instrumentedApplication *odigosv1.InstrumentedApplication
var instrumentationConfig *odigosv1.InstrumentationConfig

Describe("Delete InstrumentedApplication", func() {
Describe("Delete InstrumentationConfig", func() {

When("Namespace is not instrumented", func() {

Expand All @@ -28,20 +28,20 @@ var _ = Describe("deleteInstrumentedApplication Deployment controller", func() {
deployment = testutil.SetOdigosInstrumentationEnabled(testutil.NewMockTestDeployment(namespace))
Expect(k8sClient.Create(ctx, deployment)).Should(Succeed())

instrumentedApplication = testutil.NewMockInstrumentedApplication(deployment)
Expect(k8sClient.Create(ctx, instrumentedApplication)).Should(Succeed())
instrumentationConfig = testutil.NewMockInstrumentationConfig(deployment)
Expect(k8sClient.Create(ctx, instrumentationConfig)).Should(Succeed())
})

It("InstrumentedApplication deleted after removing instrumentation label from deployment", func() {
It("InstrumentationConfig deleted after removing instrumentation label from deployment", func() {
deployment = testutil.DeleteOdigosInstrumentationLabel(deployment)
Expect(k8sClient.Update(ctx, deployment)).Should(Succeed())
testutil.AssertInstrumentedApplicationDeleted(ctx, k8sClient, instrumentedApplication)
testutil.AssertInstrumentationConfigDeleted(ctx, k8sClient, instrumentationConfig)
})

It("InstrumentedApplication deleted after setting instrumentation label to disabled", func() {
It("InstrumentationConfig deleted after setting instrumentation label to disabled", func() {
deployment = testutil.SetOdigosInstrumentationDisabled(deployment)
Expect(k8sClient.Update(ctx, deployment)).Should(Succeed())
testutil.AssertInstrumentedApplicationDeleted(ctx, k8sClient, instrumentedApplication)
testutil.AssertInstrumentationConfigDeleted(ctx, k8sClient, instrumentationConfig)
})

})
Expand All @@ -55,20 +55,20 @@ var _ = Describe("deleteInstrumentedApplication Deployment controller", func() {
deployment = testutil.SetOdigosInstrumentationEnabled(testutil.NewMockTestDeployment(namespace))
Expect(k8sClient.Create(ctx, deployment)).Should(Succeed())

instrumentedApplication = testutil.NewMockInstrumentedApplication(deployment)
Expect(k8sClient.Create(ctx, instrumentedApplication)).Should(Succeed())
instrumentationConfig = testutil.NewMockInstrumentationConfig(deployment)
Expect(k8sClient.Create(ctx, instrumentationConfig)).Should(Succeed())
})

It("InstrumentedApplication retain when removing instrumentation label from deployment", func() {
It("InstrumentationConfig retain when removing instrumentation label from deployment", func() {
deployment = testutil.DeleteOdigosInstrumentationLabel(deployment)
Expect(k8sClient.Update(ctx, deployment)).Should(Succeed())
testutil.AssertInstrumentedApplicationRetained(ctx, k8sClient, instrumentedApplication)
testutil.AssertInstrumentationConfigRetained(ctx, k8sClient, instrumentationConfig)
})

It("InstrumentedApplication deleted after setting instrumentation label to disabled", func() {
It("InstrumentationConfig deleted after setting instrumentation label to disabled", func() {
deployment = testutil.SetOdigosInstrumentationDisabled(deployment)
Expect(k8sClient.Update(ctx, deployment)).Should(Succeed())
testutil.AssertInstrumentedApplicationDeleted(ctx, k8sClient, instrumentedApplication)
testutil.AssertInstrumentationConfigDeleted(ctx, k8sClient, instrumentationConfig)
})
})
})
Expand All @@ -83,8 +83,8 @@ var _ = Describe("deleteInstrumentedApplication Deployment controller", func() {
deployment = testutil.SetReportedNameAnnotation(deployment, "test")
Expect(k8sClient.Create(ctx, deployment)).Should(Succeed())

instrumentedApplication = testutil.NewMockInstrumentedApplication(deployment)
Expect(k8sClient.Create(ctx, instrumentedApplication)).Should(Succeed())
instrumentationConfig = testutil.NewMockInstrumentationConfig(deployment)
Expect(k8sClient.Create(ctx, instrumentationConfig)).Should(Succeed())
})

It("should delete the reported name annotation on instrumentation label deleted", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package deleteinstrumentedapplication
package deleteinstrumentationconfig

import (
"context"
Expand Down Expand Up @@ -57,24 +57,24 @@ func getObjectByOwnerReference(ctx context.Context, k8sClient client.Client, own
return nil, fmt.Errorf("unsupported owner kind %s", ownerRef.Kind)
}

type InstrumentedApplicationReconciler struct {
type InstrumentationConfigReconciler struct {
client.Client
Scheme *runtime.Scheme
}

func (r *InstrumentedApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
func (r *InstrumentationConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)

var instrumentedApplication odigosv1.InstrumentedApplication
err := r.Client.Get(ctx, req.NamespacedName, &instrumentedApplication)
var instrumentationConfig odigosv1.InstrumentationConfig
err := r.Client.Get(ctx, req.NamespacedName, &instrumentationConfig)
if err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
}

// find the workload object which is the owner of the InstrumentedApplication
ownerReferences := instrumentedApplication.GetOwnerReferences()
// find the workload object which is the owner of the InstrumentationConfig
ownerReferences := instrumentationConfig.GetOwnerReferences()
if len(ownerReferences) != 1 {
logger.Info("InstrumentedApplication should have exactly one owner reference")
logger.Info("InstrumentationConfig should have exactly one owner reference")
return ctrl.Result{}, nil
}
workloadObject, err := getObjectByOwnerReference(ctx, r.Client, ownerReferences[0], req.Namespace)
Expand All @@ -91,7 +91,7 @@ func (r *InstrumentedApplicationReconciler) Reconcile(ctx context.Context, req c

if !instEffectiveEnabled {
logger.Info("Deleting instrumented application for non-enabled workload")
err := r.Client.Delete(ctx, &instrumentedApplication)
err := r.Client.Delete(ctx, &instrumentationConfig)
return ctrl.Result{}, client.IgnoreNotFound(err)
}

Expand Down
Loading

0 comments on commit 75b6e80

Please sign in to comment.
  NODES
COMMUNITY 1
INTERN 4
Note 1
Project 3
todo 2
USERS 1