// Override only if there were definitions before (to respect the NoHeader option)
iflen(table.ColumnDefinitions)>0{
table.ColumnDefinitions=columnDefs
}
table.Rows=[]metav1.TableRow{}
fn:=func(objruntime.Object)error{
objT,ok:=obj.(T)
if!ok{
varzeroTT
returnfmt.Errorf("expected %T but got %T",zeroT,obj)
}
cells:=convertFn(objT)
iflen(cells)!=len(columnDefs){
returnfmt.Errorf("defined %d columns but got %d cells",len(columnDefs),len(cells))
}
table.Rows=append(table.Rows,metav1.TableRow{
Cells:cellStringToCellAny(cells),
Object:runtime.RawExtension{Object:obj},
})
returnnil
}
switch{
casemeta.IsListType(object):
iferr:=meta.EachListItem(object,fn);err!=nil{
returnnil,err
}
default:
iferr:=fn(object);err!=nil{
returnnil,err
}
}
returntable,nil
}
funccellStringToCellAny(cells[]string)[]any{
varres[]any
for_,cell:=rangecells{
res=append(res,cell)
}
returnres
}
// CreateOrUpdate helps implement [rest.Updater] by handling most of the logic.
//
// It will call getFn to find the object. If not found, then createFn will
// be called, which should create the object. Otherwise, the updateFn will be called,
// which should update the object.
//
// createValidation is called before createFn. It will do validation such as:
// - verifying that the user is allowed to by checking for the "create" verb.
// See here for details: https://github.com/kubernetes/apiserver/blob/70ed6fdbea9eb37bd1d7558e90c20cfe888955e8/pkg/endpoints/handlers/update.go#L190-L201
// - running mutating/validating webhooks (though we're not using them yet)
//
// updateValidation is called before updateFn. It will do validation such as:
// - running mutating/validating webhooks (though we're not using them yet)