1
0
mirror of https://github.com/rancher/types.git synced 2025-09-15 14:29:27 +00:00

Update context and status

This commit is contained in:
Darren Shepherd
2017-12-11 15:42:51 -07:00
parent 28978a4753
commit 4936f617e6
2 changed files with 40 additions and 16 deletions

View File

@@ -18,6 +18,7 @@ import (
)
type ManagementContext struct {
LocalConfig *rest.Config
RESTConfig rest.Config
UnversionedClient rest.Interface
@@ -92,14 +93,14 @@ func (c *ManagementContext) StartAndWait() error {
return ctx.Err()
}
func NewClusterContext(clusterConfig, config rest.Config, clusterName string) (*ClusterContext, error) {
func NewClusterContext(managementConfig, config rest.Config, clusterName string) (*ClusterContext, error) {
var err error
context := &ClusterContext{
RESTConfig: config,
ClusterName: clusterName,
}
context.Management, err = NewManagementContext(clusterConfig)
context.Management, err = NewManagementContext(managementConfig)
if err != nil {
return nil, err
}
@@ -155,8 +156,8 @@ func (w *ClusterContext) Start(ctx context.Context) error {
return controller.SyncThenSync(ctx, 5, controllers...)
}
func (w *ClusterContext) StartAndWait() error {
ctx := signal.SigTermCancelContext(context.Background())
func (w *ClusterContext) StartAndWait(ctx context.Context) error {
ctx = signal.SigTermCancelContext(ctx)
w.Start(ctx)
<-ctx.Done()
return ctx.Err()

View File

@@ -29,26 +29,27 @@ var conditionMappings = []conditionMapping{
Transition: true,
State: "initializing",
},
{
Name: "Ready",
Transition: true,
State: "activating",
},
{
Name: "Available",
Transition: true,
State: "activating",
},
{
Name: "Updating",
Transition: true,
FalseIsGood: true,
},
{
Name: "Progressing",
Transition: true,
State: "updating",
},
{
Name: "Provisioned",
Transition: true,
State: "provisioning",
},
{
Name: "Updating",
Transition: true,
FalseIsGood: true,
State: "updating",
},
{
Name: "ConfigOK",
Transition: true,
@@ -84,8 +85,14 @@ var conditionMappings = []conditionMapping{
FalseIsGood: true,
},
{
Name: "NetworkUnavailable",
Error: true,
Name: "NetworkUnavailable",
FalseIsGood: true,
Error: true,
},
{
Name: "KernelHasNoDeadlock",
FalseIsGood: true,
Error: true,
},
{
Name: "Unschedulable",
@@ -97,6 +104,11 @@ var conditionMappings = []conditionMapping{
Error: true,
FalseIsGood: true,
},
{
Name: "Ready",
Transition: true,
State: "activating",
},
}
func Set(data map[string]interface{}) {
@@ -120,6 +132,15 @@ func Set(data map[string]interface{}) {
val, ok = values.GetValue(data, "status", "conditions")
if !ok || val == nil {
if val, ok := values.GetValue(data, "metadata", "created"); ok {
if i, err := convert.ToTimestamp(val); err == nil {
if time.Unix(i/1000, 0).Add(5 * time.Second).Before(time.Now()) {
data["state"] = "active"
return
}
}
}
data["state"] = "initializing"
data["transitioning"] = "yes"
return
@@ -155,6 +176,8 @@ func Set(data map[string]interface{}) {
good = false
} else if !conditionMapping.FalseIsGood && condition.Status == "False" {
good = false
} else if conditionMapping.Transition && !conditionMapping.FalseIsGood && condition.Status == "Unknown" {
good = false
}
if !good && conditionMapping.Transition {