Skip to content

Commit 4766192

Browse files
committed
fix integrations status
Signed-off-by: jose.vazquez <[email protected]>
1 parent eac5bae commit 4766192

10 files changed

+152
-32
lines changed

internal/cmd/nextako/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func setupControllerRuntimeLogger() error {
108108
}
109109

110110
func startAKO(akoPath string) (*exec.Cmd, error) {
111+
//nolint:gosec
111112
cmd := exec.Command(akoPath, os.Args[1:]...)
112113
cmd.Stdout = os.Stdout
113114
cmd.Stderr = os.Stderr

internal/next-crds/atlas.nextapi.mongodb.com_atlasthirdpartyintegrations.yaml

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,24 @@ metadata:
88
spec:
99
group: atlas.nextapi.mongodb.com
1010
names:
11+
categories:
12+
- atlas
1113
kind: AtlasThirdPartyIntegration
1214
listKind: AtlasThirdPartyIntegrationList
1315
plural: atlasthirdpartyintegrations
16+
shortNames:
17+
- atpi
1418
singular: atlasthirdpartyintegration
1519
scope: Namespaced
1620
versions:
17-
- name: v1
21+
- additionalPrinterColumns:
22+
- jsonPath: .status.conditions[?(@.type=="Ready")].status
23+
name: Ready
24+
type: string
25+
- jsonPath: .status.id
26+
name: Id
27+
type: string
28+
name: v1
1829
schema:
1930
openAPIV3Schema:
2031
description: AtlasThirdPartyIntegration is the Schema for the atlas 3rd party
@@ -352,28 +363,56 @@ spec:
352363
description: Conditions is the list of statuses showing the current
353364
state of the Atlas Custom Resource
354365
items:
355-
description: Condition describes the state of an Atlas Custom Resource
356-
at a certain point.
366+
description: Condition contains details for one aspect of the current
367+
state of this API Resource.
357368
properties:
358369
lastTransitionTime:
359-
description: Last time the condition transitioned from one status
360-
to another.
370+
description: |-
371+
lastTransitionTime is the last time the condition transitioned from one status to another.
372+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
361373
format: date-time
362374
type: string
363375
message:
364-
description: A human readable message indicating details about
365-
the transition.
376+
description: |-
377+
message is a human readable message indicating details about the transition.
378+
This may be an empty string.
379+
maxLength: 32768
366380
type: string
381+
observedGeneration:
382+
description: |-
383+
observedGeneration represents the .metadata.generation that the condition was set based upon.
384+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
385+
with respect to the current state of the instance.
386+
format: int64
387+
minimum: 0
388+
type: integer
367389
reason:
368-
description: The reason for the condition's last transition.
390+
description: |-
391+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
392+
Producers of specific condition types may define expected values and meanings for this field,
393+
and whether the values are considered a guaranteed API.
394+
The value should be a CamelCase string.
395+
This field may not be empty.
396+
maxLength: 1024
397+
minLength: 1
398+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
369399
type: string
370400
status:
371-
description: Status of the condition, one of True, False, Unknown.
401+
description: status of the condition, one of True, False, Unknown.
402+
enum:
403+
- "True"
404+
- "False"
405+
- Unknown
372406
type: string
373407
type:
374-
description: Type of Atlas Custom Resource condition.
408+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
409+
maxLength: 316
410+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
375411
type: string
376412
required:
413+
- lastTransitionTime
414+
- message
415+
- reason
377416
- status
378417
- type
379418
type: object

internal/nextapi/v1/atlasthirdpartyintegration_types.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@ import (
2020
"github.com/mongodb/mongodb-atlas-kubernetes/v2/api"
2121
akov2 "github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1"
2222
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/nextapi/v1/status"
23+
ctrlstate "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/controller/state"
2324
)
2425

2526
func init() {
2627
SchemeBuilder.Register(&AtlasThirdPartyIntegration{}, &AtlasThirdPartyIntegrationList{})
2728
}
2829

30+
// AtlasThirdPartyIntegration is the Schema for the atlas 3rd party inegrations API.
31+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
2932
// +kubebuilder:object:root=true
33+
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
34+
// +kubebuilder:printcolumn:name="Id",type=string,JSONPath=`.status.id`
3035
// +kubebuilder:subresource:status
31-
32-
// AtlasThirdPartyIntegration is the Schema for the atlas 3rd party inegrations API.
36+
// +groupName:=atlas.mongodb.com
37+
// +kubebuilder:resource:categories=atlas,shortName=atpi
3338
type AtlasThirdPartyIntegration struct {
3439
metav1.TypeMeta `json:",inline"`
3540
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -38,19 +43,27 @@ type AtlasThirdPartyIntegration struct {
3843
Status status.AtlasThirdPartyIntegrationStatus `json:"status,omitempty"`
3944
}
4045

41-
func (in *AtlasThirdPartyIntegration) GetStatus() api.Status {
42-
return in.Status
43-
}
46+
// func (tpi *AtlasThirdPartyIntegration) GetStatus() api.Status {
47+
// return tpi.Status
48+
// }
49+
50+
// func (tpi *AtlasThirdPartyIntegration) UpdateStatus(conditions []metav1.Condition, _ ...api.Option) {
51+
// tpi.Status.Conditions = conditions
52+
// tpi.Status.ObservedGeneration = tpi.ObjectMeta.Generation
53+
// }
4454

45-
func (b *AtlasThirdPartyIntegration) UpdateStatus(conditions []api.Condition, _ ...api.Option) {
46-
b.Status.Conditions = conditions
47-
b.Status.ObservedGeneration = b.ObjectMeta.Generation
55+
func (tpi *AtlasThirdPartyIntegration) Credentials() *api.LocalObjectReference {
56+
return tpi.Spec.ConnectionSecret
4857
}
4958

50-
func (np *AtlasThirdPartyIntegration) Credentials() *api.LocalObjectReference {
51-
return np.Spec.ConnectionSecret
59+
func (tpi *AtlasThirdPartyIntegration) GetStatusObject() ctrlstate.StatusObject {
60+
return &tpi.Status
5261
}
5362

63+
// func (tpi *AtlasThirdPartyIntegration) GetConditions() []metav1.Condition {
64+
// return tpi.Status.GetConditions()
65+
// }
66+
5467
// +k8s:deepcopy-gen=true
5568

5669
// AtlasThirdPartyIntegrationSpec contains the expected configuration for an integration

internal/nextapi/v1/atlasthirdpartyintegration_types_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func TestIntegrationCELChecks(t *testing.T) {
204204
unstructuredObject, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&tc.obj)
205205
require.NoError(t, err)
206206

207-
crdPath := "../../next-crds/nextapi.mongodb.com_atlasthirdpartyintegrations.yaml"
207+
crdPath := "../../next-crds/atlas.nextapi.mongodb.com_atlasthirdpartyintegrations.yaml"
208208
validator, err := cel.VersionValidatorFromFile(t, crdPath, "v1")
209209
assert.NoError(t, err)
210210
errs := validator(unstructuredObject, nil)

internal/nextapi/v1/status/atlasthirdpartyintegration.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414

1515
package status
1616

17-
import (
18-
"github.com/mongodb/mongodb-atlas-kubernetes/v2/api"
19-
)
17+
// +kubebuilder:object:generate=true
2018

2119
// AtlasThirdPartyIntegrationStatus holds the status of an integration
2220
type AtlasThirdPartyIntegrationStatus struct {
23-
api.Common `json:",inline"`
21+
// UnifiedStatus holds state common to all CRDs supporting the Unified State Machine
22+
UnifiedStatus `json:",inline"`
2423

2524
// ID of the third party integration resource in Atlas
2625
ID string `json:"id"`
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package status
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// +kubebuilder:object:generate=true
8+
9+
// UnifiedStatus is shared by all CRDs supporting unified state machine
10+
type UnifiedStatus struct {
11+
// Conditions is the list of statuses showing the current state of the Atlas Custom Resource
12+
Conditions []metav1.Condition `json:"conditions"`
13+
14+
// ObservedGeneration indicates the generation of the resource specification that the Atlas Operator is aware of.
15+
// The Atlas Operator updates this field to the 'metadata.generation' as soon as it starts reconciliation of the resource.
16+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
17+
}
18+
19+
func (us *UnifiedStatus) GetConditions() []metav1.Condition {
20+
return us.Conditions
21+
}

internal/nextapi/v1/status/zz_generated.deepcopy.go

Lines changed: 41 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/state/reconciler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (r *Reconciler[T]) SetupWithManager(mgr ctrl.Manager) error {
8989

9090
func (r *Reconciler[T]) Reconcile(ctx context.Context, req ctrl.Request) (reconcile.Result, error) {
9191
logger := log.FromContext(ctx).WithName("state")
92-
logger.Info("reconcile started", "req", req)
92+
logger.Info("reconcile requested", "req", req)
9393

9494
t := new(T)
9595
obj := any(t).(client.Object)
@@ -153,7 +153,7 @@ func (r *Reconciler[T]) Reconcile(ctx context.Context, req ctrl.Request) (reconc
153153
meta.SetStatusCondition(&newStatusConditions, ready)
154154

155155
if err := patchStatus(ctx, r.cluster.GetClient(), obj, newStatus); err != nil {
156-
return ctrl.Result{}, fmt.Errorf("failed to patch status: %w", err)
156+
return ctrl.Result{}, fmt.Errorf("failed to reconcile status: %w", err)
157157
}
158158

159159
return result.Result, reconcileErr

pkg/controller/state/reconciler_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,10 @@ func (do *dummyObject) GetConditions() []metav1.Condition {
503503
return do.conditions
504504
}
505505

506+
func (do *dummyObject) GetStatusObject() StatusObject {
507+
return do
508+
}
509+
506510
func (do *dummyObject) DeepCopy() *dummyObject {
507511
if do == nil {
508512
return nil

pkg/controller/state/status.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ import (
2626
)
2727

2828
type StatusObject interface {
29-
client.Object
3029
GetConditions() []metav1.Condition
3130
}
3231

32+
type StatusHolder interface {
33+
GetStatusObject() StatusObject
34+
}
35+
3336
func newStatusObject(obj client.Object) (StatusObject, error) {
34-
statusObj, ok := obj.(StatusObject)
37+
holder, ok := obj.(StatusHolder)
3538
if ok {
36-
return statusObj, nil
39+
return holder.GetStatusObject(), nil
3740
}
38-
return nil, errors.New("object must implement StatusObject")
41+
return nil, errors.New("object must implement StatusObjeStatusHolder")
3942
}
4043

4144
func patchStatus(ctx context.Context, c client.Client, obj client.Object, status any) error {

0 commit comments

Comments
 (0)