Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement expansion template pod status (#2598)
Signed-off-by: Davis Haba <52938648+davis-haba@users.noreply.github.com> Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com>
- Loading branch information
1 parent
143e8cf
commit 7c519b4
Showing
49 changed files
with
1,753 additions
and
437 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,83 @@ | ||
package v1beta1 | ||
|
||
import ( | ||
"github.com/open-policy-agent/gatekeeper/pkg/operations" | ||
"github.com/open-policy-agent/gatekeeper/pkg/util" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
) | ||
|
||
// ExpansionTemplatePodStatusStatus defines the observed state of ExpansionTemplatePodStatus. | ||
type ExpansionTemplatePodStatusStatus struct { | ||
// Important: Run "make" to regenerate code after modifying this file | ||
ID string `json:"id,omitempty"` | ||
TemplateUID types.UID `json:"templateUID,omitempty"` | ||
Operations []string `json:"operations,omitempty"` | ||
ObservedGeneration int64 `json:"observedGeneration,omitempty"` | ||
Errors []*ExpansionTemplateError `json:"errors,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:generate=true | ||
|
||
type ExpansionTemplateError struct { | ||
Type string `json:"type,omitempty"` | ||
Message string `json:"message"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:resource:scope=Namespaced | ||
|
||
// ExpansionTemplatePodStatus is the Schema for the expansiontemplatepodstatuses API. | ||
type ExpansionTemplatePodStatus struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Status ExpansionTemplatePodStatusStatus `json:"status,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// ExpansionTemplatePodStatusList contains a list of ExpansionTemplatePodStatus. | ||
type ExpansionTemplatePodStatusList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []ExpansionTemplatePodStatus `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&ExpansionTemplatePodStatus{}, &ExpansionTemplatePodStatusList{}) | ||
} | ||
|
||
// NewExpansionTemplateStatusForPod returns an expansion template status object | ||
// that has been initialized with the bare minimum of fields to make it functional | ||
// with the expansion template status controller. | ||
func NewExpansionTemplateStatusForPod(pod *corev1.Pod, templateName string, scheme *runtime.Scheme) (*ExpansionTemplatePodStatus, error) { | ||
obj := &ExpansionTemplatePodStatus{} | ||
name, err := KeyForExpansionTemplate(pod.Name, templateName) | ||
if err != nil { | ||
return nil, err | ||
} | ||
obj.SetName(name) | ||
obj.SetNamespace(util.GetNamespace()) | ||
obj.Status.ID = pod.Name | ||
obj.Status.Operations = operations.AssignedStringList() | ||
obj.SetLabels(map[string]string{ | ||
ExpansionTemplateNameLabel: templateName, | ||
PodLabel: pod.Name, | ||
}) | ||
|
||
if err := controllerutil.SetOwnerReference(pod, obj, scheme); err != nil { | ||
return nil, err | ||
} | ||
|
||
return obj, nil | ||
} | ||
|
||
// KeyForExpansionTemplate returns a unique status object name given the Pod ID and | ||
// a template object. | ||
func KeyForExpansionTemplate(id string, templateName string) (string, error) { | ||
return DashPacker(id, templateName) | ||
} |
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
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
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
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.