Skip to content

Commit 28ae0dc

Browse files
authored
Add field to tell if a workload is deleted (#104)
* Add field to tell if a workload is deleted This state is usually temporary and should be resolved within minutes Fixes #64 * add the field to job as well * DeletedAt -> DeletionStartedAt
1 parent 9dfe98d commit 28ae0dc

File tree

8 files changed

+213
-47
lines changed

8 files changed

+213
-47
lines changed

data/k8s/dev/devteam/no-logs-for-you.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ metadata:
66
nais.io/deploymentCorrelationID: f8c04f82-6a84-4a8e-9f8b-563b5894d0cf
77
nais.io/skipDeploymentMessage: "true"
88
creationTimestamp: "2023-01-20T10:51:47Z"
9+
deletionTimestamp: "2023-01-20T10:51:47Z"
910
finalizers:
1011
- naiserator.nais.io/finalizer
1112
generation: 407981

internal/graph/gengql/generated.go

+182-47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/graph/schema/applications.graphqls

+5
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ type Application implements Node & Workload {
167167
"""
168168
before: Cursor
169169
): ApplicationInstanceConnection!
170+
171+
"""
172+
If set, when the application was marked for deletion.
173+
"""
174+
deletionStartedAt: Time
170175
}
171176

172177
"""

internal/graph/schema/jobs.graphqls

+5
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ type Job implements Node & Workload {
9696

9797
"The job manifest."
9898
manifest: JobManifest!
99+
100+
"""
101+
If set, when the job was marked for deletion.
102+
"""
103+
deletionStartedAt: Time
99104
}
100105

101106
type JobManifest implements WorkloadManifest {

internal/graph/schema/workloads.graphqls

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ interface Workload implements Node {
8585
The workload manifest.
8686
"""
8787
manifest: WorkloadManifest!
88+
89+
"""
90+
If set, when the workload was marked for deletion.
91+
"""
92+
deletionStartedAt: Time
8893
}
8994

9095
"""

internal/workload/application/models.go

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
corev1 "k8s.io/api/core/v1"
1919
"k8s.io/apimachinery/pkg/api/resource"
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/utils/ptr"
2122
)
2223

2324
type (
@@ -302,9 +303,15 @@ func toGraphApplication(application *nais_io_v1alpha1.Application, environmentNa
302303
logging = application.Spec.Observability.Logging
303304
}
304305

306+
var deletedAt *time.Time
307+
if application.DeletionTimestamp != nil {
308+
deletedAt = ptr.To(application.DeletionTimestamp.Time)
309+
}
310+
305311
return &Application{
306312
Base: workload.Base{
307313
Name: application.Name,
314+
DeletionStartedAt: deletedAt,
308315
EnvironmentName: environmentName,
309316
TeamSlug: slug.Slug(application.Namespace),
310317
ImageString: application.Spec.Image,

internal/workload/job/models.go

+6
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,15 @@ func toGraphJob(job *nais_io_v1.Naisjob, environmentName string) *Job {
327327
logging = job.Spec.Observability.Logging
328328
}
329329

330+
var deletedAt *time.Time
331+
if job.DeletionTimestamp != nil {
332+
deletedAt = ptr.To(job.DeletionTimestamp.Time)
333+
}
334+
330335
return &Job{
331336
Base: workload.Base{
332337
Name: job.Name,
338+
DeletionStartedAt: deletedAt,
333339
EnvironmentName: environmentName,
334340
TeamSlug: slug.Slug(job.Namespace),
335341
ImageString: job.Spec.Image,

internal/workload/models.go

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66
"strconv"
77
"strings"
8+
"time"
89

910
"github.com/nais/api/internal/graph/ident"
1011
"github.com/nais/api/internal/graph/model"
@@ -49,6 +50,7 @@ type Base struct {
4950
RolloutCompleteTime int64 `json:"-"`
5051
Type Type `json:"-"`
5152
Logging *nais_io_v1.Logging `json:"-"`
53+
DeletionStartedAt *time.Time `json:"deletedAt"`
5254
}
5355

5456
func (b Base) Image() *ContainerImage {

0 commit comments

Comments
 (0)