Skip to content

Commit

Permalink
feat: use omitempty in json fields
Browse files Browse the repository at this point in the history
Signed-off-by: Raphaël Pinson <[email protected]>
  • Loading branch information
raphink committed Aug 8, 2022
1 parent cb264b0 commit 17ca168
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
48 changes: 24 additions & 24 deletions clustermesh/clustermesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,16 +624,16 @@ func (k *K8sClusterMesh) Enable(ctx context.Context) error {
}

type accessInformation struct {
ServiceIPs []string `json:"service_ips"`
ServicePort int `json:"service_port"`
ClusterID string `json:"cluster_id"`
ClusterName string `json:"cluster_name"`
CA []byte `json:"ca"`
ClientCert []byte `json:"client_cert"`
ClientKey []byte `json:"client_key"`
ExternalWorkloadCert []byte `json:"external_workload_cert"`
ExternalWorkloadKey []byte `json:"external_workload_key"`
Tunnel string `json:"tunnel"`
ServiceIPs []string `json:"service_ips,omitempty"`
ServicePort int `json:"service_port,omitempty"`
ClusterID string `json:"cluster_id,omitempty"`
ClusterName string `json:"cluster_name,omitempty"`
CA []byte `json:"ca,omitempty"`
ClientCert []byte `json:"client_cert,omitempty"`
ClientKey []byte `json:"client_key,omitempty"`
ExternalWorkloadCert []byte `json:"external_workload_cert,omitempty"`
ExternalWorkloadKey []byte `json:"external_workload_key,omitempty"`
Tunnel string `json:"tunnel,omitempty"`
}

func (ai *accessInformation) etcdConfiguration() string {
Expand Down Expand Up @@ -994,9 +994,9 @@ func (k *K8sClusterMesh) Disconnect(ctx context.Context) error {
}

type Status struct {
AccessInformation *accessInformation `json:"access_information"`
Service *corev1.Service `json:"service"`
Connectivity *ConnectivityStatus `json:"connectivity"`
AccessInformation *accessInformation `json:"access_information,omitempty"`
Service *corev1.Service `json:"service,omitempty"`
Connectivity *ConnectivityStatus `json:"connectivity,omitempty"`
}

func (k *K8sClusterMesh) statusAccessInformation(ctx context.Context, log bool) (*accessInformation, error) {
Expand Down Expand Up @@ -1056,23 +1056,23 @@ func (k *K8sClusterMesh) waitForDeployment(ctx context.Context) error {
}

type StatisticalStatus struct {
Min int64 `json:"min"`
Avg float64 `json:"avg"`
Max int64 `json:"max"`
Min int64 `json:"min,omitempty"`
Avg float64 `json:"avg,omitempty"`
Max int64 `json:"max,omitempty"`
}

type ClusterStats struct {
Configured int `json:"configured"`
Connected int `json:"connected"`
Configured int `json:"configured,omitempty"`
Connected int `json:"connected,omitempty"`
}

type ConnectivityStatus struct {
GlobalServices StatisticalStatus `json:"global_services"`
Connected StatisticalStatus `json:"connected"`
Clusters map[string]*ClusterStats `json:"clusters"`
Total int64 `json:"total"`
NotReady int64 `json:"not_ready"`
Errors status.ErrorCountMapMap `json:"errors"`
GlobalServices StatisticalStatus `json:"global_services,omitempty"`
Connected StatisticalStatus `json:"connected,omitempty"`
Clusters map[string]*ClusterStats `json:"clusters,omitempty"`
Total int64 `json:"total,omitempty"`
NotReady int64 `json:"not_ready,omitempty"`
Errors status.ErrorCountMapMap `json:"errors,omitempty"`
}

func (c *ConnectivityStatus) addError(pod, cluster string, err error) {
Expand Down
14 changes: 7 additions & 7 deletions status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,29 @@ type ErrorCountMapMap map[string]ErrorCountMap
type Status struct {
// ImageCount is a map counting the number of images in use indexed by
// the image name
ImageCount MapMapCount `json:"image_count"`
ImageCount MapMapCount `json:"image_count,omitempty"`

// PhaseCount is a map counting the number of pods in each phase
// (running, failing, scheduled, ...)
PhaseCount MapMapCount `json:"phase_count"`
PhaseCount MapMapCount `json:"phase_count,omitempty"`

// PodState counts the number of pods matching conditions such as
// desired, ready, available, and unavailable
PodState PodStateMap `json:"pod_state"`
PodState PodStateMap `json:"pod_state,omitempty"`

// PodsCount is the number of pods in the k8s cluster
// all pods, and pods managed by cilium
PodsCount PodsCount `json:"pods_count"`
PodsCount PodsCount `json:"pods_count,omitempty"`

CiliumStatus CiliumStatusMap `json:"cilium_status"`
CiliumStatus CiliumStatusMap `json:"cilium_status,omitempty"`

// Errors is the aggregated errors and warnings of all pods of a
// particular deployment type
Errors ErrorCountMapMap `json:"errors"`
Errors ErrorCountMapMap `json:"errors,omitempty"`

// CollectionErrors is the errors that accumulated while collecting the
// status
CollectionErrors []error `json:"collection_errors"`
CollectionErrors []error `json:"collection_errors,omitempty"`

mutex *sync.Mutex
}
Expand Down

0 comments on commit 17ca168

Please sign in to comment.