From 634f093ab9ef36092f579c9f94be951be3191369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Thu, 7 Jul 2022 07:45:19 +0200 Subject: [PATCH] feat: use omitempty in json fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaƫl Pinson --- clustermesh/clustermesh.go | 48 +++++++++++++++++++------------------- status/status.go | 14 +++++------ 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/clustermesh/clustermesh.go b/clustermesh/clustermesh.go index 6749452123..40e3624670 100644 --- a/clustermesh/clustermesh.go +++ b/clustermesh/clustermesh.go @@ -626,16 +626,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 { @@ -1039,9 +1039,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, getExternalWorkloadSecret bool) (*accessInformation, error) { @@ -1101,23 +1101,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) { diff --git a/status/status.go b/status/status.go index cee2d1a071..3b1022d4ab 100644 --- a/status/status.go +++ b/status/status.go @@ -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 }