Skip to content

Commit

Permalink
chore(lifecycle-operator): clean up leftover logic for supporting sta…
Browse files Browse the repository at this point in the history
…ndalone Pods as Workloads (#3140)

Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
  • Loading branch information
odubajDT committed Feb 29, 2024
1 parent 86ac4ef commit 17321bc
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -202,45 +201,6 @@ func TestKeptnWorkloadVersionReconciler_reconcileDeployment_UnsupportedReference
require.Equal(t, apicommon.StateUnknown, keptnState)
}

func TestKeptnWorkloadVersionReconciler_IsPodRunning(t *testing.T) {
p1 := makeNominatedPod("pod1", "node1", v1.PodRunning)
p2 := makeNominatedPod("pod2", "node1", v1.PodPending)
podList := &v1.PodList{Items: []v1.Pod{p1, p2}}
podList2 := &v1.PodList{Items: []v1.Pod{p2}}
r := &KeptnWorkloadVersionReconciler{
Client: k8sfake.NewClientBuilder().WithLists(podList).Build(),
}
isPodRunning, err := r.isPodRunning(context.TODO(), klcv1beta1.ResourceReference{UID: "pod1"}, "node1")
require.Nil(t, err)
if !isPodRunning {
t.Errorf("Wrong!")
}

r2 := &KeptnWorkloadVersionReconciler{
Client: k8sfake.NewClientBuilder().WithLists(podList2).Build(),
}
isPodRunning, err = r2.isPodRunning(context.TODO(), klcv1beta1.ResourceReference{UID: "pod1"}, "node1")
require.Nil(t, err)
if isPodRunning {
t.Errorf("Wrong!")
}

}

func makeNominatedPod(podName string, nodeName string, phase v1.PodPhase) v1.Pod {
return v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Namespace: nodeName,
Name: podName,
UID: types.UID(podName),
},
Status: v1.PodStatus{
Phase: phase,
NominatedNodeName: nodeName,
},
}
}

func makeReplicaSet(name string, namespace string, wanted *int32, available int32) *appsv1.ReplicaSet {

return &appsv1.ReplicaSet{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ import (
apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1beta1/common"
controllererrors "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/errors"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func (r *KeptnWorkloadVersionReconciler) reconcileDeployment(ctx context.Context, workloadVersion *klcv1beta1.KeptnWorkloadVersion) (apicommon.KeptnState, error) {
var isRunning bool
var err error

switch workloadVersion.Spec.ResourceReference.Kind {
case "Pod":
isRunning, err = r.isPodRunning(ctx, workloadVersion.Spec.ResourceReference, workloadVersion.Namespace)
case "ReplicaSet":
isRunning, err = r.isReplicaSetRunning(ctx, workloadVersion.Spec.ResourceReference, workloadVersion.Namespace)
case "StatefulSet":
Expand Down Expand Up @@ -71,22 +67,6 @@ func (r *KeptnWorkloadVersionReconciler) isDaemonSetRunning(ctx context.Context,
return daemonSet.Status.DesiredNumberScheduled == daemonSet.Status.NumberReady, nil
}

func (r *KeptnWorkloadVersionReconciler) isPodRunning(ctx context.Context, resource klcv1beta1.ResourceReference, namespace string) (bool, error) {
podList := &corev1.PodList{}
if err := r.Client.List(ctx, podList, client.InNamespace(namespace)); err != nil {
return false, err
}
for _, p := range podList.Items {
if p.UID == resource.UID {
if p.Status.Phase == corev1.PodRunning {
return true, nil
}
return false, nil
}
}
return false, nil
}

func (r *KeptnWorkloadVersionReconciler) isStatefulSetRunning(ctx context.Context, resource klcv1beta1.ResourceReference, namespace string) (bool, error) {
sts := appsv1.StatefulSet{}
err := r.Client.Get(ctx, types.NamespacedName{Name: resource.Name, Namespace: namespace}, &sts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func createWorkloadInCluster(name string, namespace string, version string, appl
Spec: klcv1beta1.KeptnWorkloadSpec{
AppName: applicationName,
Version: version,
ResourceReference: klcv1beta1.ResourceReference{UID: types.UID("uid"), Kind: "Pod", Name: "pod1"},
ResourceReference: klcv1beta1.ResourceReference{UID: types.UID("uid"), Kind: "ReplicaSet", Name: "replicaset1"},
},
}
By("Invoking Reconciling for Create")
Expand Down

0 comments on commit 17321bc

Please sign in to comment.