Skip to content

Commit

Permalink
Update RepositoryServer CR Status field to add metav1.Condition (#2135
Browse files Browse the repository at this point in the history
)

* Update RepositoryServer CR Status fields, add metav1.conditions

Signed-off-by: Akanksha Kumari <akankshakumari393@gmail.com>

* Update RepositoryServer CRD

Signed-off-by: Akanksha Kumari <akankshakumari393@gmail.com>

* Run 'make codegen'

Signed-off-by: Akanksha Kumari <akankshakumari393@gmail.com>

* Fix Lint

Signed-off-by: Akanksha Kumari <akankshakumari393@gmail.com>

* Refactor name, set ClientInitialized to ClientUserInitialized

Signed-off-by: Akanksha Kumari <akankshakumari393@gmail.com>

---------

Signed-off-by: Akanksha Kumari <akankshakumari393@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
akankshakumari393 and mergify[bot] authored Jun 29, 2023
1 parent 04a9889 commit 10e1874
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 121 deletions.
40 changes: 18 additions & 22 deletions pkg/apis/cr/v1alpha1/repositoryserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,48 +117,44 @@ type UserAccess struct {

// RepositoryServerStatus is the status for the RepositoryServer. This should only be updated by the controller
type RepositoryServerStatus struct {
Conditions []Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
ServerInfo ServerInfo `json:"serverInfo,omitempty"`
Progress RepositoryServerProgress `json:"progress,omitempty"`
}

// Condition contains details of the current state of the RepositoryServer resource
type Condition struct {
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
LastUpdateTime metav1.Condition `json:"lastUpdateTime,omitempty"`
Status metav1.ConditionStatus `json:"status"`
Type RepositoryServerConditionType `json:"type"`
}
const (

// RepositoryServerConditionType defines all the various condition types of the RepositoryServer resource
type RepositoryServerConditionType string
// ServerSetup indicates whether the repository pod and service have been
ServerSetup string = "ServerSetup"

// RepositoryConnected indicates whether the existing repository is connected and ready to use
RepositoryConnected string = "RepositoryConnected"

const (
// RepositoryReady indicates whether the existing repository is connected and ready to use
RepositoryReady RepositoryServerConditionType = "RepositoryReady"
RepositoryReady string = "RepositoryReady"

// ServerInitialized means that the proxy server, that serves the repository, has been started
ServerInitialized RepositoryServerConditionType = "ServerInitialized"
ServerInitialized string = "ServerInitialized"

// ClientsInitialized indicates that the client users have been added or updated to the repository server
ClientsInitialized RepositoryServerConditionType = "ClientsInitialized"
// ClientUserInitialized indicates that the client users have been added or updated to the repository server
ClientUserInitialized string = "ClientUserInitialized"

// ServerRefreshed denotes the refreshed condition of the repository server in order to register client users
ServerRefreshed RepositoryServerConditionType = "ServerRefreshed"
ServerRefreshed string = "ServerRefreshed"
)

// RepositoryServerProgress is the field users would check to know the state of RepositoryServer
type RepositoryServerProgress string

const (
// ServerReady represents the ready state of the repository server and the pod which runs the proxy server
ServerReady RepositoryServerProgress = "ServerReady"
// Ready represents the ready state of the repository server
Ready RepositoryServerProgress = "Ready"

// ServerStopped represents the terminated state of the repository server pod due to any unforeseen errors
ServerStopped RepositoryServerProgress = "ServerStopped"
// Failed represents the terminated state of the repository server CR due to any unforeseen errors
Failed RepositoryServerProgress = "Failed"

// ServerPending indicates the pending state of the RepositoryServer CR when Reconcile callback is in progress
ServerPending RepositoryServerProgress = "ServerPending"
// Pending indicates the pending state of the RepositoryServer CR when Reconcile callback is in progress
Pending RepositoryServerProgress = "Pending"
)

// ServerInfo describes all the information required by the client users to connect to the repository server
Expand Down
21 changes: 2 additions & 19 deletions pkg/apis/cr/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pkg/controllers/repositoryserver/repositoryserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func (r *RepositoryServerReconciler) Reconcile(ctx context.Context, req ctrl.Req
return ctrl.Result{}, client.IgnoreNotFound(err)
}

logger.Info("Setting the CR status as 'ServerPending' since a create or update event is in progress")
repositoryServer.Status.Progress = crkanisteriov1alpha1.ServerPending
logger.Info("Setting the CR status as 'Pending' since a create or update event is in progress")
repositoryServer.Status.Progress = crkanisteriov1alpha1.Pending

logger.Info("Found RepositoryServer CR. Create or update owned resources")
repoServerHandler := newRepositoryServerHandler(ctx, req, logger, r, kubeCli, repositoryServer)
Expand All @@ -88,16 +88,16 @@ func (r *RepositoryServerReconciler) Reconcile(ctx context.Context, req ctrl.Req
return ctrl.Result{}, err
}
if err := repoServerHandler.CreateOrUpdateOwnedResources(ctx); err != nil {
logger.Info("Setting the CR status as 'ServerStopped' since an error occurred in create/update event")
repoServerHandler.RepositoryServer.Status.Progress = crkanisteriov1alpha1.ServerStopped
logger.Info("Setting the CR status as 'Failed' since an error occurred in create/update event")
repoServerHandler.RepositoryServer.Status.Progress = crkanisteriov1alpha1.Failed
if uerr := r.Status().Update(ctx, repoServerHandler.RepositoryServer); uerr != nil {
return ctrl.Result{}, uerr
}
r.Recorder.Event(repoServerHandler.RepositoryServer, corev1.EventTypeWarning, "Failed", err.Error())
return ctrl.Result{}, err
}
logger.Info("Setting the CR status as 'ServerReady' after completing the create/update event\n\n\n\n")
repoServerHandler.RepositoryServer.Status.Progress = crkanisteriov1alpha1.ServerReady
logger.Info("Setting the CR status as 'Ready' after completing the create/update event\n\n\n\n")
repoServerHandler.RepositoryServer.Status.Progress = crkanisteriov1alpha1.Ready
if err = r.Status().Update(ctx, repoServerHandler.RepositoryServer); err != nil {
return ctrl.Result{}, err
}
Expand Down
127 changes: 54 additions & 73 deletions pkg/customresource/repositoryserver.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down Expand Up @@ -217,88 +218,68 @@ spec:
properties:
conditions:
items:
description: Condition contains details of the current state of
the RepositoryServer resource
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
use as an array at the field path .status.conditions. For example,
\n type FooStatus struct{ // Represents the observations of a
foo's current state. // Known .status.conditions.type are: \"Available\",
\"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge
// +listType=map // +listMapKey=type Conditions []metav1.Condition
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
transitioned from one status to another. This should be when
the underlying condition changed. If that is not known, then
using the time when the API field changed is acceptable.
format: date-time
type: string
lastUpdateTime:
description: "Condition contains details for one aspect of the
current state of this API Resource. --- This struct is intended
for direct use as an array at the field path .status.conditions.
\ For example, \n type FooStatus struct{ // Represents the
observations of a foo's current state. // Known .status.conditions.type
are: \"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type
// +patchStrategy=merge // +listType=map // +listMapKey=type
Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
\n // other fields }"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
transitioned from one status to another. This should be
when the underlying condition changed. If that is not
known, then using the time when the API field changed
is acceptable.
format: date-time
type: string
message:
description: message is a human readable message indicating
details about the transition. This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: observedGeneration represents the .metadata.generation
that the condition was set based upon. For instance, if
.metadata.generation is currently 12, but the .status.conditions[x].observedGeneration
is 9, the condition is out of date with respect to the
current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: reason contains a programmatic identifier indicating
the reason for the condition's last transition. Producers
of specific condition types may define expected values
and meanings for this field, and whether the values are
considered a guaranteed API. The value should be a CamelCase
string. This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False,
Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: type of condition in CamelCase or in foo.example.com/CamelCase.
--- Many .condition.type values are consistent across
resources like Available, but because arbitrary conditions
can be useful (see .node.status.conditions), the ability
to deconflict is important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
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])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
message:
description: message is a human readable message indicating
details about the transition. This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: observedGeneration represents the .metadata.generation
that the condition was set based upon. For instance, if .metadata.generation
is currently 12, but the .status.conditions[x].observedGeneration
is 9, the condition is out of date with respect to the current
state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: reason contains a programmatic identifier indicating
the reason for the condition's last transition. Producers
of specific condition types may define expected values and
meanings for this field, and whether the values are considered
a guaranteed API. The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: RepositoryServerConditionType defines all the various
condition types of the RepositoryServer resource
description: type of condition in CamelCase or in foo.example.com/CamelCase.
--- Many .condition.type values are consistent across resources
like Available, but because arbitrary conditions can be useful
(see .node.status.conditions), the ability to deconflict is
important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
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])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
Expand Down
2 changes: 1 addition & 1 deletion pkg/kanctl/repositoryserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func waitForRepositoryServerReady(ctx context.Context, cli *kubernetes.Clientset
defer waitCancel()
pollErr := poll.Wait(timeoutCtx, func(ctx context.Context) (bool, error) {
repositoryServer, err := crCli.CrV1alpha1().RepositoryServers(rs.GetNamespace()).Get(ctx, rs.GetName(), metav1.GetOptions{})
if repositoryServer.Status.Progress == v1alpha1.ServerReady && err == nil {
if repositoryServer.Status.Progress == v1alpha1.Ready && err == nil {
return true, nil
}
return false, err
Expand Down

0 comments on commit 10e1874

Please sign in to comment.