Skip to content

Commit

Permalink
avoid lossy type conversion when parsing number of available replicas (
Browse files Browse the repository at this point in the history
  • Loading branch information
racevedoo committed Oct 31, 2019
1 parent 1e4d67d commit 1b78430
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions config/crds/apm.k8s.elastic.co_apmservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9285,6 +9285,7 @@ spec:
clusters.
type: string
availableNodes:
format: int64
type: integer
health:
description: ApmServerHealth expresses the status of the Apm Server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10527,6 +10527,7 @@ spec:
description: ElasticsearchStatus defines the observed state of Elasticsearch
properties:
availableNodes:
format: int64
type: integer
health:
description: ElasticsearchHealth is the health of the cluster as returned
Expand Down
1 change: 1 addition & 0 deletions config/crds/kibana.k8s.elastic.co_kibanas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9272,6 +9272,7 @@ spec:
description: AssociationStatus is the status of an association resource.
type: string
availableNodes:
format: int64
type: integer
health:
description: KibanaHealth expresses the status of the Kibana instances.
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/common/v1beta1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

// ReconcilerStatus represents status information about desired/available nodes.
type ReconcilerStatus struct {
AvailableNodes int `json:"availableNodes,omitempty"`
AvailableNodes int64 `json:"availableNodes,omitempty"`
}

// SecretRef is a reference to a secret that exists in the same namespace.
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/apmserver/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewState(request reconcile.Request, as *v1beta1.ApmServer) State {
// UpdateApmServerState updates the ApmServer status based on the given deployment.
func (s State) UpdateApmServerState(deployment v1.Deployment, apmServerSecret corev1.Secret) {
s.ApmServer.Status.SecretTokenSecretName = apmServerSecret.Name
s.ApmServer.Status.AvailableNodes = int(deployment.Status.AvailableReplicas) // TODO lossy type conversion
s.ApmServer.Status.AvailableNodes = int64(deployment.Status.AvailableReplicas)
s.ApmServer.Status.Health = v1beta1.ApmServerRed
for _, c := range deployment.Status.Conditions {
if c.Type == v1.DeploymentAvailable && c.Status == corev1.ConditionTrue {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/elasticsearch/reconcile/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *State) updateWithPhase(
resourcesState ResourcesState,
observedState observer.State,
) *State {
s.status.AvailableNodes = len(AvailableElasticsearchNodes(resourcesState.CurrentPods))
s.status.AvailableNodes = int64(len(AvailableElasticsearchNodes(resourcesState.CurrentPods)))
s.status.Phase = phase

s.status.Health = v1beta1.ElasticsearchUnknownHealth
Expand Down Expand Up @@ -76,7 +76,7 @@ func (s *State) IsElasticsearchReady(observedState observer.State) bool {

// UpdateElasticsearchApplyingChanges marks Elasticsearch as being the applying changes phase in the resource status.
func (s *State) UpdateElasticsearchApplyingChanges(pods []corev1.Pod) *State {
s.status.AvailableNodes = len(AvailableElasticsearchNodes(pods))
s.status.AvailableNodes = int64(len(AvailableElasticsearchNodes(pods)))
s.status.Phase = v1beta1.ElasticsearchApplyingChangesPhase
s.status.Health = v1beta1.ElasticsearchRedHealth
return s
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/kibana/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewState(request reconcile.Request, kb *v1beta1.Kibana) State {

// UpdateKibanaState updates the Kibana status based on the given deployment.
func (s State) UpdateKibanaState(deployment v1.Deployment) {
s.Kibana.Status.AvailableNodes = int(deployment.Status.AvailableReplicas) // TODO lossy type conversion
s.Kibana.Status.AvailableNodes = int64(deployment.Status.AvailableReplicas)
s.Kibana.Status.Health = v1beta1.KibanaRed
for _, c := range deployment.Status.Conditions {
if c.Type == v1.DeploymentAvailable && c.Status == corev1.ConditionTrue {
Expand Down

0 comments on commit 1b78430

Please sign in to comment.