1
0
mirror of https://github.com/rancher/types.git synced 2025-09-01 05:09:10 +00:00

Update vendor

This commit is contained in:
Darren Shepherd
2018-01-16 18:07:49 -07:00
parent 5c4bc1a5a6
commit 8ff4eea093
6 changed files with 84 additions and 48 deletions

View File

@@ -20,6 +20,14 @@ func (c Cond) IsTrue(obj runtime.Object) bool {
return getStatus(obj, string(c)) == "True"
}
func (c Cond) LastUpdated(obj runtime.Object, ts string) {
setTS(obj, string(c), ts)
}
func (c Cond) GetLastUpdated(obj runtime.Object) string {
return getTS(obj, string(c))
}
func (c Cond) False(obj runtime.Object) {
setStatus(obj, string(c), "False")
}
@@ -28,10 +36,22 @@ func (c Cond) IsFalse(obj runtime.Object) bool {
return getStatus(obj, string(c)) == "False"
}
func (c Cond) GetStatus(obj runtime.Object) string {
return getStatus(obj, string(c))
}
func (c Cond) Unknown(obj runtime.Object) {
setStatus(obj, string(c), "Unknown")
}
func (c Cond) CreateUnknownIfNotExists(obj runtime.Object) {
condSlice := getValue(obj, "Status", "Conditions")
cond := findCond(condSlice, string(c))
if cond == nil {
c.Unknown(obj)
}
}
func (c Cond) IsUnknown(obj runtime.Object) bool {
return getStatus(obj, string(c)) == "Unknown"
}
@@ -43,7 +63,7 @@ func (c Cond) Reason(obj runtime.Object, reason string) {
func (c Cond) Message(obj runtime.Object, message string) {
cond := findOrCreateCond(obj, string(c))
getFieldValue(cond, "Message").SetString(message)
setValue(cond, "Message", message)
}
func (c Cond) GetMessage(obj runtime.Object) string {
@@ -76,23 +96,7 @@ func (c Cond) Once(obj runtime.Object, f func() (runtime.Object, error)) (runtim
}
}
if c.IsTrue(obj) {
return obj, nil
}
c.Unknown(obj)
newObj, err := f()
if newObj != nil && !reflect.ValueOf(newObj).IsNil() {
obj = newObj
}
if err != nil {
c.False(obj)
c.ReasonAndMessageFromError(obj, err)
return obj, err
}
c.True(obj)
return obj, nil
return c.DoUntilTrue(obj, f)
}
func (c Cond) DoUntilTrue(obj runtime.Object, f func() (runtime.Object, error)) (runtime.Object, error) {
@@ -100,20 +104,7 @@ func (c Cond) DoUntilTrue(obj runtime.Object, f func() (runtime.Object, error))
return obj, nil
}
c.Unknown(obj)
newObj, err := f()
if newObj != nil && !reflect.ValueOf(newObj).IsNil() {
obj = newObj
}
if err != nil {
c.ReasonAndMessageFromError(obj, err)
return obj, err
}
c.True(obj)
c.Reason(obj, "")
c.Message(obj, "")
return obj, nil
return c.do(obj, f)
}
func (c Cond) Do(obj runtime.Object, f func() (runtime.Object, error)) (runtime.Object, error) {
@@ -121,14 +112,37 @@ func (c Cond) Do(obj runtime.Object, f func() (runtime.Object, error)) (runtime.
}
func (c Cond) do(obj runtime.Object, f func() (runtime.Object, error)) (runtime.Object, error) {
c.Unknown(obj)
status := c.GetStatus(obj)
ts := c.GetLastUpdated(obj)
reason := c.GetReason(obj)
message := c.GetMessage(obj)
obj, err := c.doInternal(obj, f)
// This is to prevent non stop flapping of states and update
if status == c.GetStatus(obj) &&
reason == c.GetReason(obj) &&
message == c.GetMessage(obj) {
c.LastUpdated(obj, ts)
}
return obj, err
}
func (c Cond) doInternal(obj runtime.Object, f func() (runtime.Object, error)) (runtime.Object, error) {
if !c.IsFalse(obj) {
c.Unknown(obj)
}
newObj, err := f()
if newObj != nil && !reflect.ValueOf(newObj).IsNil() {
obj = newObj
}
if err != nil {
c.False(obj)
if _, ok := err.(*controller.ForgetError); !ok {
c.False(obj)
}
c.ReasonAndMessageFromError(obj, err)
return obj, err
}
@@ -148,6 +162,16 @@ func getStatus(obj interface{}, condName string) string {
return getFieldValue(cond, "Status").String()
}
func setTS(obj interface{}, condName, ts string) {
cond := findOrCreateCond(obj, condName)
getFieldValue(cond, "LastUpdateTime").SetString(ts)
}
func getTS(obj interface{}, condName string) string {
cond := findOrCreateCond(obj, condName)
return getFieldValue(cond, "LastUpdateTime").String()
}
func setStatus(obj interface{}, condName, status string) {
cond := findOrCreateCond(obj, condName)
setValue(cond, "Status", status)

View File

@@ -224,7 +224,7 @@ func generateScheme(external bool, outputDir string, version *types.APIVersion,
if !external {
names = append(names, schema.CodeName)
}
if schema.CanList() {
if schema.CanList(nil) {
names = append(names, schema.CodeName+"List")
}
}

View File

@@ -155,7 +155,7 @@ func (s *Schemas) importType(version *APIVersion, t reflect.Type, overrides ...r
mappers := s.mapper(&schema.Version, schema.ID)
if s.DefaultMappers != nil {
if schema.CanList() {
if schema.CanList(nil) {
mappers = append(s.DefaultMappers(), mappers...)
}
}
@@ -179,7 +179,7 @@ func (s *Schemas) importType(version *APIVersion, t reflect.Type, overrides ...r
mapper := &typeMapper{
Mappers: mappers,
root: schema.CanList(),
root: schema.CanList(nil),
}
if err := mapper.ModifySchema(schema, s); err != nil {

View File

@@ -21,18 +21,30 @@ func (v *APIVersion) Equals(other *APIVersion) bool {
v.Path == other.Path
}
func (s *Schema) CanList() bool {
return slice.ContainsString(s.CollectionMethods, http.MethodGet)
func (s *Schema) CanList(context *APIContext) bool {
if context == nil {
return slice.ContainsString(s.CollectionMethods, http.MethodGet)
}
return context.AccessControl.CanList(context, s)
}
func (s *Schema) CanCreate() bool {
return slice.ContainsString(s.CollectionMethods, http.MethodPost)
func (s *Schema) CanCreate(context *APIContext) bool {
if context == nil {
return slice.ContainsString(s.CollectionMethods, http.MethodPost)
}
return context.AccessControl.CanCreate(context, s)
}
func (s *Schema) CanUpdate() bool {
return slice.ContainsString(s.ResourceMethods, http.MethodPut)
func (s *Schema) CanUpdate(context *APIContext) bool {
if context == nil {
return slice.ContainsString(s.ResourceMethods, http.MethodPut)
}
return context.AccessControl.CanUpdate(context, nil, s)
}
func (s *Schema) CanDelete() bool {
return slice.ContainsString(s.ResourceMethods, http.MethodDelete)
func (s *Schema) CanDelete(context *APIContext) bool {
if context == nil {
return slice.ContainsString(s.ResourceMethods, http.MethodDelete)
}
return context.AccessControl.CanDelete(context, nil, s)
}

View File

@@ -68,8 +68,8 @@ type ResponseWriter interface {
type AccessControl interface {
CanCreate(apiContext *APIContext, schema *Schema) bool
CanList(apiContext *APIContext, schema *Schema) bool
CanUpdate(apiContext *APIContext, schema *Schema) bool
CanDelete(apiContext *APIContext, schema *Schema) bool
CanUpdate(apiContext *APIContext, obj map[string]interface{}, schema *Schema) bool
CanDelete(apiContext *APIContext, obj map[string]interface{}, schema *Schema) bool
Filter(apiContext *APIContext, obj map[string]interface{}, context map[string]string) map[string]interface{}
FilterList(apiContext *APIContext, obj []map[string]interface{}, context map[string]string) []map[string]interface{}