In kubectl/run.go
in Kubernetes code, the Generate
function has a result list of these two types:
runtime.Object, error
The last line of the function is:
return &deployment, nil
runtime
is imported:
k8s.io/apimachinery/pkg/runtime
I got runtime
by running go get
on that import statement, and Object is defined in interfaces.go
:
type Object interface {
GetObjectKind() schema.ObjectKind
DeepCopyObject() Object
}
(And I found the same code on the web here.)
The address operator creates a pointer... more specifically, the Go spec states:
For an operand x of type T, the address operation &x generates a pointer of type *T to x.
and pointers have a type distinct from their base type:
A pointer type denotes the set of all pointers to variables of a given type, called the base type of the pointer.
How does &deployment
satisfy the runtime.Object
type?
My best guess so far is that deployment
implements the runtime.Object
interface, and mapping &deployment
to runtime.Object
satisfies this rule of assignability:
T is an interface type and x implements T.
and that a return statement mapping to a result list type is equivalent to assignment in this respect. Is this correct? If not, is there another part of the specification or documentation that explains it?