Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Feature/check min agent version #314

Merged
merged 50 commits into from
Sep 17, 2020
Merged

Conversation

DTMad
Copy link
Member

@DTMad DTMad commented Sep 14, 2020

No description provided.

DTMad and others added 30 commits September 8, 2020 09:47
# Conflicts:
#	pkg/controller/oneagent/oneagent_controller.go
#	pkg/controller/oneagent/oneagent_utils.go
#	pkg/controller/oneagent/oneagent_utils_test.go
# Conflicts:
#	pkg/controller/oneagent/oneagent_controller.go
#	pkg/controller/oneagent/oneagent_update.go
#	pkg/controller/utils/cluster_version.go
#	pkg/controller/utils/cluster_version_test.go
Co-authored-by: Michael Rynkiewicz <michaelrynkiewicz3@gmail.com>
…trace-oneagent-operator into feature/AddImmutableImage
# Conflicts:
#	pkg/controller/oneagent/oneagent_controller.go
@DTMad DTMad requested a review from lrgar September 14, 2020 05:25
go.sum Outdated
@@ -1,56 +1,91 @@
bazil.org/fuse v0.0.0-20160811212531-371fbbdaa898/go.mod h1:Xbm+BRKSBEpa4q4hTSxohYNQpsxXPbPry4JJWOB3LB8=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can discard the changes to this file since there are none in go.mod.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here remains.


const updateInterval = 5 * time.Minute

type Operator interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used at all? And if so, there is reconcile.Reconcile already.

metav1.Now().UTC().Sub(instance.GetStatus().LastClusterVersionProbeTimestamp.UTC()) > updateInterval {
instance.GetStatus().LastClusterVersionProbeTimestamp = metav1.Now()
instance.GetStatus().UseImmutableImage =
instance.GetSpec().UseImmutableImage &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upper if already checks for instance.GetSpec().UseImmutableImage to be true.

// LastClusterVersionProbeTimestamp status is the duration of updateInterval behind
// otherwise returns false
func SetUseImmutableImageStatus(logger logr.Logger, instance v1alpha1.BaseOneAgent, agentVersion string, dtc dtclient.Client) bool {
if dtc == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fair, we're ignoring whether the parameters can be nil pretty much everywhere.

@@ -43,6 +43,7 @@ func Add(mgr manager.Manager) error {
dtcReconciler: &utils.DynatraceClientReconciler{
Client: client,
UpdatePaaSToken: true,
UpdateAPIToken: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this is true only when immutable images are used. For customers upgrading they would receive errors for the missing ApiToken even if it doesn't affect them.

func TestIsAgentVersionSupported(t *testing.T) {
logger := logf.ZapLoggerTo(os.Stdout, true)

t.Run("IsAgentVersionSupported", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the subtest?

}

func extractVersion(versionString string) (*versionInfo, error) {
mainVersionRegex := regexp.MustCompile(`[\d]+\.[\d]+\.[\d]+`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An example version is 1.203.12.20200914-092723 - I wonder if, for development pipelines, the first three fields remain the same, but the later changes.

Also, regexp.MustCompile is to be used as a global variable.

mainVersionRegex := regexp.MustCompile(`[\d]+\.[\d]+\.[\d]+`)
mainVersion := mainVersionRegex.FindString(versionString)

versionMergeRegex := regexp.MustCompile(`[\d]+`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Golang supports groups/submatches which is what you're trying to get here: https://golang.org/pkg/regexp/#Regexp.FindStringSubmatch

You could also just split the string by dot.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to FindStringSubmatch.

Splitting the string by dots returns 3 values for e.g.: 1.203.0 but 4 values for e.g.: 1.203.0.20200915-101926. Opted for regex to keep that more consistent.
Furthermore the used regex checks if the values between dots are actually numbers which makes checking for a malformed version string easier

Comment on lines 42 to 43
comparision, err := compareVersionInfo(agentVersion, minSupportedAgentVersion)
return comparision >= 0, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
comparision, err := compareVersionInfo(agentVersion, minSupportedAgentVersion)
return comparision >= 0, err
comparison, err := compareVersionInfo(agentVersion, minSupportedAgentVersion)
return comparison >= 0, err

// n > 0: if a > b
// n < 0: if a < b
// 0 with error: if a == nil || b == nil
func compareVersionInfo(a *versionInfo, b *versionInfo) (int, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to remove the pointers, and just assume they are correct and leave the error verification problem to an upper level when it can actually be wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointers here are used to avoid pass-by-value due to higher memory consumption

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are supposed to be executed every 5 minutes, so that's not really a problem.

… into feature/check-min-agent-version

# Conflicts:
#	deploy/cr.yaml
#	go.sum
#	pkg/controller/oneagent/oneagent_controller.go
#	pkg/controller/oneagent/oneagent_update.go
#	pkg/webhook/bootstrapper/controller.go
@meik99 meik99 requested a review from lrgar September 16, 2020 07:37
pkg/controller/istio/controller.go Outdated Show resolved Hide resolved
go.sum Outdated
@@ -1,56 +1,91 @@
bazil.org/fuse v0.0.0-20160811212531-371fbbdaa898/go.mod h1:Xbm+BRKSBEpa4q4hTSxohYNQpsxXPbPry4JJWOB3LB8=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here remains.

pkg/controller/nodes/nodes_controller.go Outdated Show resolved Hide resolved
pkg/controller/nodes/nodes_controller_test.go Outdated Show resolved Hide resolved
// n > 0: if a > b
// n < 0: if a < b
// 0 with error: if a == nil || b == nil
func compareVersionInfo(a *versionInfo, b *versionInfo) (int, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are supposed to be executed every 5 minutes, so that's not really a problem.

pkg/controller/oneagent/oneagent_controller_test.go Outdated Show resolved Hide resolved
Comment on lines 100 to 104
if instance.Spec.UseImmutableImage {
r.dtcReconciler.UpdateAPIToken = true
}

dtc, upd, err := r.dtcReconciler.Reconcile(context.TODO(), instance)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically r.dtcReconciler is at risk of race conditions if multiple OneAgentAPM Reconcile calls are running in parallel. I think by default running reconciliation in parallel is disabled so it's not a problem now, but I'd suggest the changes below (in part to avoid changes on global objects),

Suggested change
if instance.Spec.UseImmutableImage {
r.dtcReconciler.UpdateAPIToken = true
}
dtc, upd, err := r.dtcReconciler.Reconcile(context.TODO(), instance)
dtcRec := *r.dtcReconciler
if instance.Spec.UseImmutableImage {
dtcRec.UpdateAPIToken = true
}
dtc, upd, err := dtcRec.Reconcile(context.TODO(), instance)

@@ -5,7 +5,7 @@ import (
"os"
"testing"

"github.com/Dynatrace/dynatrace-oneagent-operator/pkg/apis"
apis "github.com/Dynatrace/dynatrace-oneagent-operator/pkg/apis"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
apis "github.com/Dynatrace/dynatrace-oneagent-operator/pkg/apis"
"github.com/Dynatrace/dynatrace-oneagent-operator/pkg/apis"

@@ -166,7 +166,7 @@ func handleCommunicationHosts(request *http.Request, writer http.ResponseWriter)
switch request.Method {
case "GET":
writer.WriteHeader(http.StatusOK)
_, _ = writer.Write(commHostOutput)
_, _ = writer.Write([]byte(commHostOutput))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_, _ = writer.Write([]byte(commHostOutput))
_, _ = writer.Write(commHostOutput)

Comment on lines 22 to 23
const testNamespace = "dynatrace"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused.

version := versionRegex.FindStringSubmatch(versionString)

if len(version) < 4 {
return nil, fmt.Errorf("version malformed: %s", versionString)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case, things such as versionRegex.FindStringSubmatch("asdadasdsd.asd1.2.3") would pass the validation, although they most certainly won't happen.

instance.GetStatus().LastClusterVersionProbeTimestamp = metav1.Now()
instance.GetStatus().UseImmutableImage =
version.IsRemoteClusterVersionSupported(logger, dtc) &&
version.IsAgentVersionSupported(logger, agentVersion)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also the OneAgent version configured on the cluster.

For example, customer installing Operator in a new environment using our instructions and we have .spec.useImmutableImage enabled by default in our example, their cluster supports images, but the OneAgent version they want to use (and it's configured on Dynatrace, i.e., not on .spec) doesn't, we need to disable immutable image for this case.

In fact the version on .spec is not particularly relevant since we don't modify the installer URL anyway if the version is unsupported.

This may not be an uncommon situation at the beginning once we release this feature.

meik99 and others added 5 commits September 16, 2020 13:42
Co-authored-by: Luis Garcia <luis.garcia@dynatrace.com>
Co-authored-by: Luis Garcia <luis.garcia@dynatrace.com>
Co-authored-by: Luis Garcia <luis.garcia@dynatrace.com>
Co-authored-by: Luis Garcia <luis.garcia@dynatrace.com>
…lues

changed agent version string source from cr to cluster
removed unnecessary aliases
rolled back go.sum to master branch version
@meik99 meik99 requested a review from lrgar September 17, 2020 04:16
agentVersion, err := dtc.GetLatestAgentVersion(dtclient.OsUnix, dtclient.InstallerTypeDefault)
if err == nil {
instance.GetStatus().UseImmutableImage =
version.IsRemoteClusterVersionSupported(logger, dtc) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume the issue with agent version failing also applies to fetching the remote cluster version, doesn't it? That is, a network glitch may disable immutable images temporarily.

@meik99 meik99 requested a review from lrgar September 17, 2020 07:37
@meik99 meik99 merged commit cc0a3e7 into master Sep 17, 2020
@DTMad DTMad deleted the feature/check-min-agent-version branch September 22, 2020 12:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants