This repository has been archived by the owner on Jun 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Workload Identity status condition (#714)
* status * update code * hack/update-codegen.sh + UT coverage * fix typo * update code * update code * update code * update code
- Loading branch information
1 parent
194c0e0
commit f1babc0
Showing
43 changed files
with
869 additions
and
669 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright 2020 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"knative.dev/pkg/apis" | ||
) | ||
|
||
func (s *IdentityStatus) MarkWorkloadIdentityConfigured(cs *apis.ConditionSet) { | ||
cs.Manage(s).MarkTrue(IdentityConfigured) | ||
} | ||
|
||
func (s *IdentityStatus) MarkWorkloadIdentityNotConfigured(cs *apis.ConditionSet, reason, messageFormat string, messageA ...interface{}) { | ||
cs.Manage(s).MarkUnknown(IdentityConfigured, reason, messageFormat, messageA...) | ||
} | ||
|
||
func (s *IdentityStatus) MarkWorkloadIdentityFailed(cs *apis.ConditionSet, reason, messageFormat string, messageA ...interface{}) { | ||
cs.Manage(s).MarkFalse(IdentityConfigured, reason, messageFormat, messageA...) | ||
// Set ConditionReady to be false. | ||
// ConditionType IdentityConfigured is not included in apis.NewLivingConditionSet{}, so it is not counted for conditionReady. | ||
// This is because if Workload Identity is not enabled, IdentityConfigured will be unknown. | ||
// It will be counted for conditionReady only if it is failed. | ||
cs.Manage(s).MarkFalse(apis.ConditionReady, "WorkloadIdentityFailed", messageFormat, messageA...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright 2020 Google LLC. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"knative.dev/pkg/apis" | ||
"testing" | ||
) | ||
|
||
func TestMarkWorkloadIdentityConfigured(t *testing.T) { | ||
status := &IdentityStatus{} | ||
condSet := apis.NewLivingConditionSet() | ||
status.MarkWorkloadIdentityConfigured(&condSet) | ||
got := status.IsReady() | ||
want := true | ||
if got != want { | ||
t.Errorf("unexpected readiness: want %v, got %v", want, got) | ||
} | ||
} | ||
|
||
func TestMarkWorkloadIdentityNotConfigured(t *testing.T) { | ||
status := &IdentityStatus{} | ||
condSet := apis.NewLivingConditionSet() | ||
status.MarkWorkloadIdentityFailed(&condSet, "failed", "failed") | ||
got := status.IsReady() | ||
want := false | ||
if got != want { | ||
t.Errorf("unexpected readiness: want %v, got %v", want, got) | ||
} | ||
} | ||
|
||
func TestMarkWorkloadIdentityFailed(t *testing.T) { | ||
status := &IdentityStatus{} | ||
condSet := apis.NewLivingConditionSet() | ||
status.MarkWorkloadIdentityNotConfigured(&condSet, "failed", "failed") | ||
got := status.IsReady() | ||
want := true | ||
if got != false { | ||
t.Errorf("unexpected readiness: want %v, got %v", want, got) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2020 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"knative.dev/pkg/apis" | ||
duckv1 "knative.dev/pkg/apis/duck/v1" | ||
) | ||
|
||
type IdentitySpec struct { | ||
// ServiceAccount is the GCP service account which has required permissions to poll from a Cloud Pub/Sub subscription. | ||
// If not specified, defaults to use secret. | ||
// +optional | ||
// TODO rename ServiceAccount, issue https://github.com/google/knative-gcp/issues/723 | ||
ServiceAccount string `json:"serviceAccount,omitempty"` | ||
} | ||
|
||
// IdentityStatus inherits duck/v1 Status and adds a ServiceAccountName. | ||
type IdentityStatus struct { | ||
// Inherits duck/v1 Status,, which currently provides: | ||
// * ObservedGeneration - the 'Generation' of the Service that was last processed by the controller. | ||
// * Conditions - the latest available observations of a resource's current state. | ||
duckv1.Status `json:",inline"` | ||
// ServiceAccountName is the k8s service account associated with Google service account. | ||
ServiceAccountName string `json:"serviceAccountName,omitempty"` | ||
} | ||
|
||
const ( | ||
IdentityConfigured apis.ConditionType = "WorkloadIdentityConfigured" | ||
) | ||
|
||
// IsReady returns true if the resource is ready overall. | ||
func (ss *IdentityStatus) IsReady() bool { | ||
for _, c := range ss.Conditions { | ||
switch c.Type { | ||
// Look for the "happy" condition, which is the only condition that | ||
// we can reliably understand to be the overall state of the resource. | ||
case apis.ConditionReady, apis.ConditionSucceeded: | ||
return c.IsTrue() | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright 2020 Google LLC. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"github.com/google/go-cmp/cmp" | ||
"testing" | ||
) | ||
|
||
func TestIsReady(t *testing.T) { | ||
status := &IdentityStatus{} | ||
want := false | ||
|
||
got := status.IsReady() | ||
|
||
if diff := cmp.Diff(want, got); diff != "" { | ||
t.Errorf("Unexpected difference (-want, +got): %v", diff) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.