Skip to content

Commit

Permalink
Fixed OLM UI to show Pie chart
Browse files Browse the repository at this point in the history
  • Loading branch information
redhatHameed authored and Roddie Kieley committed Jul 18, 2019
1 parent 7dbc5ff commit 2783ed9
Show file tree
Hide file tree
Showing 12 changed files with 612 additions and 29 deletions.
16 changes: 11 additions & 5 deletions Gopkg.lock

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

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ required = [
# branch = "master" #osdk_branch_annotation
version = "=v0.5.0" #osdk_version_annotation

[[constraint]]
name = "github.com/RHsyseng/operator-utils"
revision = "232650febd728455482b3c780c79a9ac0be62b50"

[prune]
go-tests = true
non-go = true
Expand Down
5 changes: 5 additions & 0 deletions deploy/crds/broker_v1alpha1_activemqartemis_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ spec:
type: object
status:
type: object
properties:
pods:
items:
type: object
type: object
version: v1alpha1
versions:
- name: v1alpha1
Expand Down
11 changes: 8 additions & 3 deletions pkg/apis/broker/v1alpha1/activemqartemis_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
"github.com/RHsyseng/operator-utils/pkg/olm"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -31,9 +32,8 @@ type CommonConfig struct {
// ActiveMQArtemisStatus defines the observed state of ActiveMQArtemis
// +k8s:openapi-gen=true
type ActiveMQArtemisStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
// Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html
//PodStatus AMQPodStatus `json:"pods"`
PodStatus olm.DeploymentStatus `json:"pods"`
}

type SSLConfig struct {
Expand Down Expand Up @@ -73,3 +73,8 @@ type ActiveMQArtemisList struct {
func init() {
SchemeBuilder.Register(&ActiveMQArtemis{}, &ActiveMQArtemisList{})
}

//type AMQPodStatus struct {
//Ready []string `json:"ready,omitempty"`
//Unavailable []string `json:"unavailable,omitempty"`
//}
3 changes: 2 additions & 1 deletion pkg/apis/broker/v1alpha1/zz_generated.deepcopy.go

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

97 changes: 96 additions & 1 deletion pkg/controller/activemqartemis/creatingk8sresources_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package activemqartemis

import (
"context"
"github.com/RHsyseng/operator-utils/pkg/olm"
brokerv1alpha1 "github.com/rh-messaging/activemq-artemis-operator/pkg/apis/broker/v1alpha1"
svc "github.com/rh-messaging/activemq-artemis-operator/pkg/resources/services"
ss "github.com/rh-messaging/activemq-artemis-operator/pkg/resources/statefulsets"
"github.com/rh-messaging/activemq-artemis-operator/pkg/utils/fsm"
"reflect"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -144,7 +147,7 @@ func (rs *CreatingK8sResourcesState) Update() (error, int) {

break
}

updataPodStatus(rs)
return err, nextStateID
}

Expand All @@ -156,3 +159,95 @@ func (rs *CreatingK8sResourcesState) Exit() error {

return nil
}

/*func getPodNamesObj(pods []corev1.Pod) brokerv1alpha1.AMQPodNames {
var ready, unavailable, names []string
ready = append(ready, "---")
unavailable = append(unavailable, "---")
return brokerv1alpha1.AMQPodNames{
PodName: names,
Ready: ready,
Unavailable: unavailable,
}
}
*/

func updataPodStatus(rs *CreatingK8sResourcesState) error {

reqLogger := log.WithValues("ActiveMQArtemis Name", rs.parentFSM.customResource.Name)
reqLogger.Info("Updating pods status")

//podStatus := getPodDeploymentStatus(rs.parentFSM.r, rs.parentFSM.customResource)
podStatus := getPodStatus(rs.parentFSM.r, rs.parentFSM.customResource)

reqLogger.Info("PpodStatus are to be updated.............................", "info:", podStatus)
reqLogger.Info("Ready Count........................", "info:", len(podStatus.Ready))
//reqLogger.Info("Unavailable Count.............................", "info:", len(podStatus.Unavailable))
reqLogger.Info("Stopped Count........................", "info:", len(podStatus.Stopped))
reqLogger.Info("Starting Count........................", "info:", len(podStatus.Starting))

if !reflect.DeepEqual(podStatus, rs.parentFSM.customResource.Status.PodStatus) {

rs.parentFSM.customResource.Status.PodStatus = podStatus

err := rs.parentFSM.r.client.Status().Update(context.TODO(), rs.parentFSM.customResource)
if err != nil {
reqLogger.Error(err, "Failed to update pods status")
return err
}
reqLogger.Info("Pods status updated")
return nil
}

return nil

}
//func getPodDeploymentStatus(r *ReconcileActiveMQArtemis, instance *brokerv1alpha1.ActiveMQArtemis) brokerv1alpha1.AMQPodStatus {
//// List the pods for this deployment
//log.Info("making", " method", " call")
//
//var ready, unavailable []string
//var startCnt int32 = 0
//var readyCnt int32 = 0
//
//depFound := &appsv1.StatefulSet{}
//err := r.client.Get(context.TODO(), types.NamespacedName{Name: instance.Name + "-ss", Namespace: instance.Namespace}, depFound)

func getPodStatus(r *ReconcileActiveMQArtemis, instance *brokerv1alpha1.ActiveMQArtemis) olm.DeploymentStatus {
// List the pods for this deployment
var status olm.DeploymentStatus
sfsFound := &appsv1.StatefulSet{}

err := r.client.Get(context.TODO(), types.NamespacedName{Name: instance.Name + "-ss", Namespace: instance.Namespace}, sfsFound)
if err == nil {
//log.Info("--Replicas--------------", "ReadyReplicas: ", depFound.Status.ReadyReplicas, " Total Replicas ", depFound.Status.Replicas)
//readyCnt = depFound.Status.ReadyReplicas
//startCnt = depFound.Status.Replicas - readyCnt
status = olm.GetSingleStatefulSetStatus(*sfsFound)
} else {
dsFound := &appsv1.DaemonSet{}
err = r.client.Get(context.TODO(), types.NamespacedName{Name: instance.Name, Namespace: instance.Namespace}, dsFound)
if err == nil {
//log.Info("daemonset exist:", " replias: ", dsFound.Status.NumberReady, " - ", dsFound.Status.NumberAvailable)
//readyCnt = dsFound.Status.NumberReady
//startCnt = dsFound.Status.NumberAvailable - readyCnt
status = olm.GetSingleDaemonSetStatus(*dsFound)
}
}
//for i := int32(0); i < startCnt; {
//unavailable = append(unavailable, "pod")
//i++
//}
//for i := int32(0); i < readyCnt; {
//ready = append(ready, "pod")
//i++
//}
//return brokerv1alpha1.AMQPodStatus{
//
//Ready: ready,
//Unavailable: unavailable,
//}
return status
}

136 changes: 136 additions & 0 deletions vendor/github.com/RHsyseng/operator-utils/pkg/olm/deployment_status.go

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

0 comments on commit 2783ed9

Please sign in to comment.