-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Dynatrace/APM-236993/update-activegate-ver…
…sion Automatically update ActiveGate pod
- Loading branch information
Showing
27 changed files
with
772 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,3 +76,4 @@ tags | |
.history | ||
# End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode | ||
/.idea/ | ||
/debug.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
package activegate | ||
|
||
import ( | ||
"github.com/Dynatrace/dynatrace-activegate-operator/pkg/apis" | ||
"github.com/operator-framework/operator-sdk/pkg/k8sutil" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
"os" | ||
_const "github.com/Dynatrace/dynatrace-activegate-operator/pkg/controller/const" | ||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/kubectl/pkg/scheme" | ||
"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
"testing" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
if err := apis.AddToScheme(scheme.Scheme); err != nil { | ||
log.Error(err, err.Error()) | ||
func TestUpdatePods(t *testing.T) { | ||
fakeClient := fake.NewFakeClientWithScheme( | ||
scheme.Scheme, | ||
NewSecret("activegate", "dynatrace", map[string]string{_const.DynatraceApiToken: "42", _const.DynatracePaasToken: "84"}), | ||
) | ||
r := ReconcileActiveGate{ | ||
client: fakeClient, | ||
} | ||
if err := os.Setenv(k8sutil.WatchNamespaceEnvVar, "dynatrace"); err != nil { | ||
log.Error(err, err.Error()) | ||
request := reconcile.Request{} | ||
|
||
reconciliation, err := r.Reconcile(request) | ||
|
||
assert.NotNil(t, reconciliation) | ||
assert.Nil(t, err) | ||
} | ||
|
||
func NewSecret(name, namespace string, kv map[string]string) *corev1.Secret { | ||
data := make(map[string][]byte) | ||
for k, v := range kv { | ||
data[k] = []byte(v) | ||
} | ||
m.Run() | ||
return &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace}, Data: data} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package activegate | ||
|
||
import ( | ||
"context" | ||
dynatracev1alpha1 "github.com/Dynatrace/dynatrace-activegate-operator/pkg/apis/dynatrace/v1alpha1" | ||
"github.com/Dynatrace/dynatrace-activegate-operator/pkg/controller/builder" | ||
corev1 "k8s.io/api/core/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
"time" | ||
) | ||
|
||
func (r *ReconcileActiveGate) createNewPod(pod *corev1.Pod, instance *dynatracev1alpha1.ActiveGate, secret *corev1.Secret) (reconcile.Result, error) { | ||
log.Info("creating new Pod", "Pod.Namespace", pod.Namespace, "Pod.Name", pod.Name) | ||
err := r.client.Create(context.TODO(), pod) | ||
if err != nil { | ||
return reconcile.Result{}, err | ||
} | ||
// Sleep until pod is ready | ||
time.Sleep(TimeUntilActive) | ||
|
||
return builder.ReconcileAfterFiveMinutes(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package activegate | ||
|
||
import ( | ||
"context" | ||
"github.com/go-logr/logr" | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
) | ||
|
||
func (r *ReconcileActiveGate) deletePods(logger logr.Logger, pods []v1.Pod) error { | ||
for _, pod := range pods { | ||
logger.Info("deleting outdated pod", "pod", pod.Name, "node", pod.Spec.NodeName) | ||
err := r.client.Delete(context.TODO(), &pod) | ||
if err != nil && !errors.IsNotFound(err) { | ||
// Not an error if pod is already gone | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.