Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

195
Vistas
JSON parsing of ClusterRole in Go is not working

I have a problem parsing the metadata in ClusterRole object from Json in Go.

I made this example:

package main

import (
    "encoding/json"
    "fmt"

    "k8s.io/kubernetes/pkg/apis/rbac"
)

func main() {
    clusterDemo := rbac.ClusterRole{}

    clusterRolesRaw := `{
        "apiVersion": "rbac.authorization.k8s.io/v1",
        "kind": "ClusterRole",
        "metadata": {
            "creationTimestamp": "2021-01-21T08:07:13Z",
            "managedFields": [],
            "name": "kubeadm:get-nodes",
            "resourceVersion": "220",
            "uid": "c78a8b10-cd20-4b64-8e4d-4f7f758c7b65"
        },
        "rules": []
    }`
    err := json.Unmarshal([]byte(clusterRolesRaw), &clusterDemo)
    if err != nil {
        fmt.Printf("unmarshal file: %v", err)
    }
    fmt.Printf("Name: %s\n", clusterDemo.Name)
    fmt.Printf("Kind: %s\n", clusterDemo.Kind)
}

Run it with

# go get -v ./... 
# go run <filename>
Name: 
Kind: ClusterRole

As you can see, the Kind field is parsed, but the Name field (part of the metadata) is not.

My question is why? It looks like the nested structure is not parsed.

Any help is appreciated, I think I am missing something

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Change your import from "k8s.io/kubernetes/pkg/apis/rbac" to rbac "k8s.io/api/rbac/v1".

It should work.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda