Skip to content

Commit

Permalink
More volume fixes and state changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Mar 23, 2018
1 parent c8a2bab commit 2831798
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 37 deletions.
9 changes: 9 additions & 0 deletions apis/project.cattle.io/v3/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,21 @@ func volumeTypes(schemas *types.Schemas) *types.Schemas {
AddMapperForType(&Version, v1.PersistentVolumeClaimVolumeSource{},
&m.Move{From: "claimName", To: "persistentVolumeClaimName"},
).
AddMapperForType(&Version, v1.VolumeMount{},
m.Required{Fields: []string{
"mountPath",
"name",
}},
).
MustImport(&Version, v1.PersistentVolumeClaimVolumeSource{}, struct {
ClaimName string `norman:"type=reference[persistentVolumeClaim]"`
}{}).
MustImport(&Version, v1.SecretVolumeSource{}, struct {
SecretName string `norman:"type=reference[secret]"`
}{}).
MustImport(&Version, v1.VolumeMount{}, struct {
MountPath string `json:"mountPath" norman:"required"`
}{}).
MustImport(&Version, v1.Volume{}, struct {
}{}).
MustImport(&Version, v1.PersistentVolumeSpec{}, struct {
Expand Down
6 changes: 5 additions & 1 deletion mapper/namespace_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ func (n *NamespaceReference) FromInternal(data map[string]interface{}) {
func (n *NamespaceReference) ToInternal(data map[string]interface{}) {
for _, path := range n.fields {
convert.Transform(data, path, func(input interface{}) interface{} {
return strings.SplitN(convert.ToString(input), ":", 2)[0]
parts := strings.SplitN(convert.ToString(input), ":", 2)
if len(parts) == 2 {
return parts[1]
}
return parts[0]
})
}
}
Expand Down
96 changes: 60 additions & 36 deletions status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var transitioningMap = map[string]string{
"Active": "activating",
"AddonDeploy": "deploying",
"AgentDeployed": "installing",
"Available": "activating",
"BackingNamespaceCreated": "configuring",
"ConfigOK": "configuring",
"Created": "creating",
Expand All @@ -44,7 +43,6 @@ var transitioningMap = map[string]string{
"NodesCreated": "provisioning",
"Pending": "pending",
"PodScheduled": "scheduling",
"Progressing": "updating",
"Provisioned": "provisioning",
"Registered": "registering",
"Removed": "removing",
Expand Down Expand Up @@ -81,6 +79,14 @@ var errorMapping = map[string]bool{
var doneMap = map[string]string{
"Completed": "activating",
"Ready": "unavailable",
"Available": "updating",
}

// True == transitioning
// False ==
// Unknown ==
var progressMap = map[string]string{
"Progressing": "progressing",
}

func concat(str, next string) string {
Expand Down Expand Up @@ -117,40 +123,6 @@ func Set(data map[string]interface{}) {
}
}

val, ok := values.GetValue(data, "metadata", "removed")
if ok && val != "" && val != nil {
data["state"] = "removing"
data["transitioning"] = "yes"

finalizers, ok := values.GetStringSlice(data, "metadata", "finalizers")
if !ok {
finalizers, ok = values.GetStringSlice(data, "spec", "finalizers")
}

msg := ""
for _, cond := range conditions {
if cond.Type == "Removed" && (cond.Status == "Unknown" || cond.Status == "False") && cond.Message != "" {
msg = cond.Message
}
}

if ok && len(finalizers) > 0 {
if len(msg) > 0 {
msg = msg + "; waiting on " + finalizers[0]
} else {
msg = "waiting on " + finalizers[0]
}
data["transitioningMessage"] = msg
if i, err := convert.ToTimestamp(val); err == nil {
if time.Unix(i/1000, 0).Add(5 * time.Minute).Before(time.Now()) {
data["transitioning"] = "error"
}
}
}

return
}

state := ""
error := false
transitioning := false
Expand Down Expand Up @@ -209,6 +181,21 @@ func Set(data map[string]interface{}) {
}
}

for _, c := range conditions {
if state != "" {
break
}
newState, ok := progressMap[c.Type]
if !ok {
continue
}
if c.Status == "True" {
transitioning = true
state = newState
message = concat(message, c.Message)
}
}

if state == "" {
val, ok := values.GetValue(data, "spec", "active")
if ok {
Expand Down Expand Up @@ -253,4 +240,41 @@ func Set(data map[string]interface{}) {

data["state"] = strings.ToLower(state)
data["transitioningMessage"] = message

val, ok := values.GetValue(data, "metadata", "removed")
if ok && val != "" && val != nil {
data["state"] = "removing"
data["transitioning"] = "yes"

finalizers, ok := values.GetStringSlice(data, "metadata", "finalizers")
if !ok {
finalizers, ok = values.GetStringSlice(data, "spec", "finalizers")
}

msg := message
for _, cond := range conditions {
if cond.Type == "Removed" && (cond.Status == "Unknown" || cond.Status == "False") && cond.Message != "" {
msg = cond.Message
}
}

if ok && len(finalizers) > 0 {
parts := strings.Split(finalizers[0], "controller.cattle.io/")
f := parts[len(parts)-1]

if len(msg) > 0 {
msg = msg + "; waiting on " + f
} else {
msg = "waiting on " + f
}
data["transitioningMessage"] = msg
if i, err := convert.ToTimestamp(val); err == nil {
if time.Unix(i/1000, 0).Add(5 * time.Minute).Before(time.Now()) {
data["transitioning"] = "error"
}
}
}

return
}
}

0 comments on commit 2831798

Please sign in to comment.