-
Notifications
You must be signed in to change notification settings - Fork 48
Conversation
# Conflicts: # pkg/controller/oneagent/oneagent_controller.go # pkg/controller/oneagent/oneagent_utils.go # pkg/controller/oneagent/oneagent_utils_test.go
…feature/AddImmutableImage
# 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
go.sum
Outdated
@@ -1,56 +1,91 @@ | |||
bazil.org/fuse v0.0.0-20160811212531-371fbbdaa898/go.mod h1:Xbm+BRKSBEpa4q4hTSxohYNQpsxXPbPry4JJWOB3LB8= |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 && |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
pkg/version/agent_version_test.go
Outdated
func TestIsAgentVersionSupported(t *testing.T) { | ||
logger := logf.ZapLoggerTo(os.Stdout, true) | ||
|
||
t.Run("IsAgentVersionSupported", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the subtest?
pkg/version/version_info.go
Outdated
} | ||
|
||
func extractVersion(versionString string) (*versionInfo, error) { | ||
mainVersionRegex := regexp.MustCompile(`[\d]+\.[\d]+\.[\d]+`) |
There was a problem hiding this comment.
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.
pkg/version/version_info.go
Outdated
mainVersionRegex := regexp.MustCompile(`[\d]+\.[\d]+\.[\d]+`) | ||
mainVersion := mainVersionRegex.FindString(versionString) | ||
|
||
versionMergeRegex := regexp.MustCompile(`[\d]+`) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
pkg/version/agent_version.go
Outdated
comparision, err := compareVersionInfo(agentVersion, minSupportedAgentVersion) | ||
return comparision >= 0, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comparision, err := compareVersionInfo(agentVersion, minSupportedAgentVersion) | |
return comparision >= 0, err | |
comparison, err := compareVersionInfo(agentVersion, minSupportedAgentVersion) | |
return comparison >= 0, err |
pkg/version/version_info.go
Outdated
// 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
go.sum
Outdated
@@ -1,56 +1,91 @@ | |||
bazil.org/fuse v0.0.0-20160811212531-371fbbdaa898/go.mod h1:Xbm+BRKSBEpa4q4hTSxohYNQpsxXPbPry4JJWOB3LB8= |
There was a problem hiding this comment.
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/version/version_info.go
Outdated
// 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) { |
There was a problem hiding this comment.
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.
if instance.Spec.UseImmutableImage { | ||
r.dtcReconciler.UpdateAPIToken = true | ||
} | ||
|
||
dtc, upd, err := r.dtcReconciler.Reconcile(context.TODO(), instance) |
There was a problem hiding this comment.
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),
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_, _ = writer.Write([]byte(commHostOutput)) | |
_, _ = writer.Write(commHostOutput) |
const testNamespace = "dynatrace" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused.
pkg/version/version_info.go
Outdated
version := versionRegex.FindStringSubmatch(versionString) | ||
|
||
if len(version) < 4 { | ||
return nil, fmt.Errorf("version malformed: %s", versionString) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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
agentVersion, err := dtc.GetLatestAgentVersion(dtclient.OsUnix, dtclient.InstallerTypeDefault) | ||
if err == nil { | ||
instance.GetStatus().UseImmutableImage = | ||
version.IsRemoteClusterVersionSupported(logger, dtc) && |
There was a problem hiding this comment.
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.
No description provided.