{"record":{"id":"5a38dca9596e97ec","repo":"kubernetes/kops","slug":"parsing-reference-q-v","errorCode":null,"errorMessage":"parsing reference %q: %v","messagePattern":"parsing reference %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/assets/assetcopy/copyimage.go","lineNumber":43,"sourceCode":"\t\"github.com/google/go-containerregistry/pkg/v1/types\"\n\t\"k8s.io/klog/v2\"\n)\n\n// CopyImage copies a docker image from a source registry, to a target registry,\n// typically used for highly secure clusters.\ntype CopyImage struct {\n\tName        string\n\tSourceImage string\n\tTargetImage string\n}\n\nfunc (e *CopyImage) Run() error {\n\tsource := e.SourceImage\n\ttarget := e.TargetImage\n\n\tsourceRef, err := name.ParseReference(source)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"parsing reference %q: %v\", source, err)\n\t}\n\n\ttargetRef, err := name.ParseReference(target)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"parsing reference for %q: %v\", target, err)\n\t}\n\n\toptions := []remote.Option{remote.WithAuthFromKeychain(authn.DefaultKeychain)}\n\n\tdesc, err := remote.Get(sourceRef, options...)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"fetching %q: %v\", source, err)\n\t}\n\n\ttargetDesc, err := remote.Get(targetRef, options...)\n\tif err == nil && desc.Digest.String() == targetDesc.Digest.String() {\n\t\tklog.Infof(\"no need to copy image from %v to %v\", sourceRef, targetRef)\n\t\treturn nil","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/assets/assetcopy/copyimage.go#L25-L61","documentation":"CopyImage.Run wraps the failure of go-containerregistry's name.ParseReference on the SOURCE image string. ParseReference validates that the string is a well-formed container image reference (registry host, repository path, optional tag/digest). kOps re-wraps the underlying parse error as \"parsing reference %q: %v\" so the invalid source image is named in the message.","triggerScenarios":"CopyImage.Run is called with SourceImage that name.ParseReference rejects: empty string, invalid characters, malformed repository name, a tag/digest that violates the reference grammar (e.g. '!!bad tag', 'registry/repo::tag'), or an invalid registry host (wrong port, underscore in hostname).","commonSituations":"Misconfigured kops cluster spec ( Assets container / cluster spec assets fields) where the image URL was hand-edited; templated values left unfilled (e.g. '{{ .Image }}'); typo'd registry host like 'registry-1.io//repo'; using ':' or '@' incorrectly in a digest reference.","solutions":["Fix the SourceImage value in the kops cluster spec (spec.assets) to a valid image reference like 'registry.k8s.io/kops/kube-apiserver:v1.x.y'.","Test the string with `go-containerregistry`'s crane or `name.ParseReference` locally to see the exact grammar complaint.","Check for unexpanded template variables or duplicated slashes/colons in the configured image URL.","If the image has no tag, note ParseReference defaults to :latest; add an explicit tag or digest to be safe."],"exampleFix":"// before\nCopyImage{SourceImage: \"registry.k8s.io/kops/ kube-apiserver:v1.28.0\", TargetImage: \"...\"}\n// after\nCopyImage{SourceImage: \"registry.k8s.io/kops/kube-apiserver:v1.28.0\", TargetImage: \"...\"}","handlingStrategy":"validation","validationCode":"func validImageRef(ref string) bool {\n\t_, err := name.ParseReference(ref)\n\treturn err == nil\n}\n\nif !validImageRef(src.SourceImage) {\n\treturn fmt.Errorf(\"invalid SourceImage reference: %q\", src.SourceImage)\n}","typeGuard":null,"tryCatchPattern":"var cerr *name.ErrBadName\nif errors.As(err, &cerr) {\n\tlog.Printf(\"bad image reference, fix cluster spec assets: %v\", cerr)\n} else if err != nil {\n\treturn err\n}","preventionTips":["Validate spec.assets image strings with `crane digest` before running kops update.","Use fully qualified references with an explicit tag or digest — never rely on :latest.","Avoid hand-editing image URLs; use `kops set cluster` / templating that is lint-checked.","Reject strings containing '://' or whitespace early in your config pipeline."],"tags":["container-image","input-validation","image-reference"],"backgroundTag":"invalid-image-reference","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}