diff --git a/pkg/apis/serving/v1alpha1/knativeserving_lifecycle.go b/pkg/apis/serving/v1alpha1/knativeserving_lifecycle.go index d13181e0..788ee718 100644 --- a/pkg/apis/serving/v1alpha1/knativeserving_lifecycle.go +++ b/pkg/apis/serving/v1alpha1/knativeserving_lifecycle.go @@ -21,6 +21,7 @@ import ( ) var conditions = apis.NewLivingConditionSet( + DependenciesInstalled, DeploymentsAvailable, InstallSucceeded, ) @@ -56,6 +57,10 @@ func (is *KnativeServingStatus) IsDeploying() bool { return is.IsInstalled() && !is.IsAvailable() } +func (is *KnativeServingStatus) IsFullySupported() bool { + return is.GetCondition(DependenciesInstalled).IsTrue() +} + func (is *KnativeServingStatus) GetCondition(t apis.ConditionType) *apis.Condition { return conditions.Manage(is).GetCondition(t) } @@ -73,6 +78,10 @@ func (is *KnativeServingStatus) MarkInstallFailed(msg string) { func (is *KnativeServingStatus) MarkInstallSucceeded() { conditions.Manage(is).MarkTrue(InstallSucceeded) + if is.GetCondition(DependenciesInstalled).IsUnknown() { + // Assume deps are installed if we're not sure + is.MarkDependenciesInstalled() + } } func (is *KnativeServingStatus) MarkDeploymentsAvailable() { @@ -85,3 +94,21 @@ func (is *KnativeServingStatus) MarkDeploymentsNotReady() { "NotReady", "Waiting on deployments") } + +func (is *KnativeServingStatus) MarkDependenciesInstalled() { + conditions.Manage(is).MarkTrue(DependenciesInstalled) +} + +func (is *KnativeServingStatus) MarkDependencyInstalling(msg string) { + conditions.Manage(is).MarkFalse( + DependenciesInstalled, + "Installing", + "Dependency installing: %s", msg) +} + +func (is *KnativeServingStatus) MarkDependencyMissing(msg string) { + conditions.Manage(is).MarkFalse( + DependenciesInstalled, + "Error", + "Dependency missing: %s", msg) +} diff --git a/pkg/apis/serving/v1alpha1/knativeserving_lifecycle_test.go b/pkg/apis/serving/v1alpha1/knativeserving_lifecycle_test.go index 735ade5c..b082fdde 100644 --- a/pkg/apis/serving/v1alpha1/knativeserving_lifecycle_test.go +++ b/pkg/apis/serving/v1alpha1/knativeserving_lifecycle_test.go @@ -32,3 +32,22 @@ func TestKnativeServingGroupVersionKind(t *testing.T) { t.Errorf("got: %v, want: %v", got, want) } } + +func TestAssumeDepsInstalled(t *testing.T) { + ks := &KnativeServingStatus{} + ks.InitializeConditions() + assertEqual(t, ks.GetCondition(DependenciesInstalled).IsUnknown(), true) + assertEqual(t, ks.GetCondition(DependenciesInstalled).IsTrue(), false) + ks.MarkInstallSucceeded() + assertEqual(t, ks.GetCondition(DependenciesInstalled).IsUnknown(), false) + assertEqual(t, ks.GetCondition(DependenciesInstalled).IsTrue(), true) + assertEqual(t, ks.IsInstalled(), true) + assertEqual(t, ks.IsFullySupported(), true) +} + +func assertEqual(t *testing.T, actual, expected interface{}) { + if actual == expected { + return + } + t.Fatalf("Expected: %v\nActual: %v", expected, actual) +} diff --git a/pkg/apis/serving/v1alpha1/knativeserving_types.go b/pkg/apis/serving/v1alpha1/knativeserving_types.go index c4ea7320..80065546 100644 --- a/pkg/apis/serving/v1alpha1/knativeserving_types.go +++ b/pkg/apis/serving/v1alpha1/knativeserving_types.go @@ -25,8 +25,9 @@ import ( // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. const ( - InstallSucceeded apis.ConditionType = "InstallSucceeded" - DeploymentsAvailable apis.ConditionType = "DeploymentsAvailable" + DependenciesInstalled apis.ConditionType = "DependenciesInstalled" + InstallSucceeded apis.ConditionType = "InstallSucceeded" + DeploymentsAvailable apis.ConditionType = "DeploymentsAvailable" ) // Registry defines image overrides of knative images.