Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge main #1

Merged
merged 9 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
- uses: lycheeverse/lychee-action@v1.10.0
with:
args: >-
-v -n "*.md" "**/*.md"
-v -n "*.md" "**/*.md" "**/*.mdx"
--exclude "http://localhost*"
--exclude "^https://logs-prod.*"
--exclude ".*your-account.*"
--exclude ".*qryn.local.*"
fail: true
62 changes: 62 additions & 0 deletions api/config/crd/bases/odigos.io_collectorsgroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,68 @@ spec:
status:
description: CollectorsGroupStatus defines the observed state of Collector
properties:
conditions:
description: |-
Represents the observations of a collectorsroup's current state.
Known .status.conditions.type are: "Available", "Progressing"
items:
description: Condition contains details for one aspect of the current
state of this API Resource.
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: type of condition in CamelCase or in foo.example.com/CamelCase.
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
ready:
type: boolean
receiverSignals:
Expand Down

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

8 changes: 8 additions & 0 deletions api/odigos/v1alpha1/collectorsgroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ type CollectorsGroupStatus struct {
// this is used to determine if a workload should export each signal or not.
// this list is calculated based on the odigos destinations that were configured
ReceiverSignals []common.ObservabilitySignal `json:"receiverSignals,omitempty"`

// Represents the observations of a collectorsroup's current state.
// Known .status.conditions.type are: "Available", "Progressing"
// +patchMergeKey=type
// +patchStrategy=merge
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
}

//+genclient
Expand Down
19 changes: 13 additions & 6 deletions api/odigos/v1alpha1/zz_generated.deepcopy.go

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

44 changes: 44 additions & 0 deletions autoscaler/controllers/common/deployedcondition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package common

import (
"encoding/json"
"time"

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

func GetCollectorsGroupDeployedConditionsPatch(err error) string {

status := metav1.ConditionTrue
if err != nil {
status = metav1.ConditionFalse
}

message := "Gateway collector is deployed in the cluster"
if err != nil {
message = err.Error()
}

reason := "GatewayDeployedCreatedSuccessfully"
if err != nil {
// in the future, we can be more specific and break it down to
// more detailed reasons about what exactly failed
reason = "GatewayDeployedCreationFailed"
}

patch := map[string]interface{}{
"status": map[string]interface{}{
"conditions": []metav1.Condition{{
Type: "Deployed",
Status: status,
Reason: reason,
Message: message,
LastTransitionTime: metav1.NewTime(time.Now()),
}},
},
}

patchData, _ := json.Marshal(patch)
// marshal error is ignored as it is not expected to happen
return string(patchData)
}
14 changes: 13 additions & 1 deletion autoscaler/controllers/datacollection/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -56,17 +57,28 @@ func (dm *DelayManager) RunSyncDaemonSetWithDelayAndSkipNewCalls(delay time.Dura

// Finish the function execution after the delay
time.AfterFunc(delay, func() {
var err error
logger := log.FromContext(ctx)

dm.mu.Lock()
defer dm.mu.Unlock()
defer dm.finishProgress()
var err error
defer func() {
statusPatchString := common.GetCollectorsGroupDeployedConditionsPatch(err)
statusErr := c.Status().Patch(ctx, collection, client.RawPatch(types.MergePatchType, []byte(statusPatchString)))
if statusErr != nil {
logger.Error(statusErr, "Failed to patch collectors group status")
// just log the error, do not fail the reconciliation
}
}()

for i := 0; i < retries; i++ {
_, err = syncDaemonSet(ctx, dests, collection, c, scheme, secrets, version)
if err == nil {
return
}
}

log.FromContext(ctx).Error(err, "Failed to sync DaemonSet")
})
}
Expand Down
55 changes: 22 additions & 33 deletions autoscaler/controllers/gateway/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

"errors"

"github.com/odigos-io/odigos/autoscaler/utils"
"github.com/odigos-io/odigos/k8sutils/pkg/consts"

Expand Down Expand Up @@ -37,49 +39,37 @@ func syncDeployment(dests *odigosv1.DestinationList, gateway *odigosv1.Collector

secretsVersionHash, err := destinationsSecretsVersionsHash(ctx, c, dests)
if err != nil {
logger.Error(err, "Failed to get secrets hash")
return nil, err
return nil, errors.Join(err, errors.New("failed to get secrets hash"))
}

// Calculate the hash of the config data and the secrets version hash, this is used to make sure the gateway will restart when the config changes
configDataHash := common.Sha256Hash(fmt.Sprintf("%s-%s", configData, secretsVersionHash))
desiredDeployment, err := getDesiredDeployment(dests, configDataHash, gateway, scheme, imagePullSecrets, odigosVersion, memConfig)
if err != nil {
logger.Error(err, "Failed to get desired deployment")
return nil, err
return nil, errors.Join(err, errors.New("failed to get desired deployment"))
}

existing := &appsv1.Deployment{}
if err := c.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, existing); err != nil {
if apierrors.IsNotFound(err) {
logger.V(0).Info("Creating deployment")
newDeployment, err := createDeployment(desiredDeployment, ctx, c)
if err != nil {
logger.Error(err, "failed to create deployment")
return nil, err
}
return newDeployment, nil
} else {
logger.Error(err, "failed to get deployment")
return nil, err
}
existingDeployment := &appsv1.Deployment{}
getError := c.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, existingDeployment)
if getError != nil && !apierrors.IsNotFound(getError) {
return nil, errors.Join(getError, errors.New("failed to get gateway deployment"))
}

logger.V(0).Info("Patching deployment")
newDep, err := patchDeployment(existing, desiredDeployment, ctx, c)
if err != nil {
logger.Error(err, "failed to patch deployment")
return nil, err
}

return newDep, nil
}

func createDeployment(desired *appsv1.Deployment, ctx context.Context, c client.Client) (*appsv1.Deployment, error) {
if err := c.Create(ctx, desired); err != nil {
return nil, err
if apierrors.IsNotFound(getError) {
logger.V(0).Info("Creating new gateway deployment")
err := c.Create(ctx, desiredDeployment)
if err != nil {
return nil, errors.Join(err, errors.New("failed to create gateway deployment"))
}
return desiredDeployment, nil
} else {
logger.V(0).Info("Patching existing gateway deployment")
newDep, err := patchDeployment(existingDeployment, desiredDeployment, ctx, c)
if err != nil {
return nil, errors.Join(err, errors.New("failed to patch gateway deployment"))
}
return newDep, nil
}
return desired, nil
}

func patchDeployment(existing *appsv1.Deployment, desired *appsv1.Deployment, ctx context.Context, c client.Client) (*appsv1.Deployment, error) {
Expand All @@ -90,7 +80,6 @@ func patchDeployment(existing *appsv1.Deployment, desired *appsv1.Deployment, ct
})

if err != nil {
logger.Error(err, "Failed to patch deployment")
return nil, err
}

Expand Down
Loading