-
Notifications
You must be signed in to change notification settings - Fork 394
fix: k8s resource nil point #2216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ou 8000 r terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -23,7 +23,11 @@ func (m *metaCollector) processDeploymentEntity(data *k8smeta.ObjectWrapper, met | |||
log.Contents.Add("labels", m.processEntityJSONObject(obj.Labels)) | |||
log.Contents.Add("annotations", m.processEntityJSONObject(obj.Annotations)) | |||
log.Contents.Add("match_labels", m.processEntityJSONObject(obj.Spec.Selector.MatchLabels)) | |||
log.Contents.Add("replicas", strconv.FormatInt(int64(*obj.Spec.Replicas), 10)) | |||
if obj.Spec.Replicas != nil { | |||
log.Contents.Add("replicas", strconv.FormatInt(int64(*obj.Spec.Replicas), 10)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if else有点多,能否封装下函数
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@@ -209,7 +209,11 @@ func (m *metaCollector) processPersistentVolumeEntity(data *k8smeta.ObjectWrappe | |||
log.Contents.Add("status", string(obj.Status.Phase)) | |||
log.Contents.Add("storage_class_name", obj.Spec.StorageClassName) | |||
log.Contents.Add("persistent_volume_reclaim_policy", string(obj.Spec.PersistentVolumeReclaimPolicy)) | |||
log.Contents.Add("volume_mode", string(*obj.Spec.VolumeMode)) | |||
if obj.Spec.VolumeMode != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为什么还是if esle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个字段的类型是type VolumeMode string 特殊的,没有可以复用的地方
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其他保留if else的都是这个原因
问题
K8s资源中,这类虽然有默认值的指针,在通过client-go获取时仍然可能是空的。
解决方案