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 30, 2019
1 parent 1e4d67d commit 63951be
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
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 63951be

Please sign in to comment.