-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AgentAction controller #73
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
10db807
Include manager image in bundle
carolynvs 739b940
Add AgentAction controller
carolynvs 39e653a
Use a constant for the default porter agent version
carolynvs 01879ba
Sync go.mod
carolynvs 3a4addb
Bump schemaversion used in test param/creds
carolynvs ca09693
Review feedback
carolynvs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -22,7 +22,7 @@ jobs: | |
- name: Setup Porter | ||
uses: getporter/[email protected] | ||
with: | ||
porter_version: v1.0.0-alpha.8 | ||
porter_version: v1.0.0-alpha.12 | ||
- name: Set up Mage | ||
run: go run mage.go EnsureMage | ||
- name: Test | ||
|
@@ -48,4 +48,4 @@ jobs: | |
if: ${{ github.event_name != 'pull_request' }} | ||
run: mage -v Publish | ||
env: | ||
ENV: production | ||
PORTER_ENV: production |
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
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,40 @@ | ||||||
package v1 | ||||||
|
||||||
// AgentPhase are valid status of a Porter agent job | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// that is managing a change to a Porter resource. | ||||||
type AgentPhase string | ||||||
|
||||||
const ( | ||||||
// PhaseUnknown means that we don't know what porter is doing yet. | ||||||
PhaseUnknown AgentPhase = "Unknown" | ||||||
|
||||||
// PhasePending means that Porter's execution is pending. | ||||||
PhasePending AgentPhase = "Pending" | ||||||
|
||||||
// PhaseRunning indicates that Porter is running. | ||||||
PhaseRunning AgentPhase = "Running" | ||||||
|
||||||
// PhaseSucceeded means that calling Porter succeeded. | ||||||
PhaseSucceeded AgentPhase = "Succeeded" | ||||||
|
||||||
// PhaseFailed means that calling Porter failed. | ||||||
PhaseFailed AgentPhase = "Failed" | ||||||
) | ||||||
|
||||||
// AgentConditionType are valid conditions of a Porter agent job | ||||||
// that is managing a change to a Porter resource. | ||||||
type AgentConditionType string | ||||||
|
||||||
const ( | ||||||
// ConditionScheduled means that the Porter agent has been scheduled. | ||||||
ConditionScheduled AgentConditionType = "Scheduled" | ||||||
|
||||||
// ConditionStarted means that the Porter agent has started. | ||||||
ConditionStarted AgentConditionType = "Started" | ||||||
|
||||||
// ConditionComplete means the Porter agent has completed successfully. | ||||||
ConditionComplete AgentConditionType = "Completed" | ||||||
|
||||||
// ConditionFailed means the Porter agent failed. | ||||||
ConditionFailed AgentConditionType = "Failed" | ||||||
) |
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,100 @@ | ||
package v1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// AgentActionSpec defines the desired state of AgentAction | ||
type AgentActionSpec struct { | ||
// AgentConfig is the name of an AgentConfig to use instead of the AgentConfig defined at the namespace or system level. | ||
// +optional | ||
AgentConfig *corev1.LocalObjectReference `json:"agentConfig,omitempty"` | ||
|
||
// PorterConfig is the name of a PorterConfig to use instead of the PorterConfig defined at the namespace or system level. | ||
PorterConfig *corev1.LocalObjectReference `json:"porterConfig,omitempty"` | ||
|
||
// Command to run inside the Porter Agent job. Defaults to running the agent. | ||
Command []string `json:"command,omitempty"` | ||
|
||
// Args to pass to the Porter Agent job. This should be the porter command that you want to run. | ||
Args []string `json:"args,omitempty"` | ||
|
||
// Files that should be present in the working directory where the command is run. | ||
Files map[string][]byte `json:"files,omitempty"` | ||
|
||
// Env variables to set on the Porter Agent job. | ||
Env []corev1.EnvVar `json:"env,omitempty"` | ||
|
||
// EnvFrom allows setting environment variables on the Porter Agent job, using secrets or config maps as the source. | ||
EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"` | ||
|
||
// VolumeMounts that should be defined on the Porter Agent job. | ||
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"` | ||
|
||
// Volumes that should be defined on the Porter Agent job. | ||
Volumes []corev1.Volume `json:"volumes,omitempty"` | ||
} | ||
|
||
// AgentActionStatus defines the observed state of AgentAction | ||
type AgentActionStatus struct { | ||
// The last generation observed by the controller. | ||
ObservedGeneration int64 `json:"observedGeneration,omitempty"` | ||
|
||
// The currently active job that is running the Porter Agent. | ||
Job *corev1.LocalObjectReference `json:"job,omitempty"` | ||
|
||
// The current status of the agent. | ||
// Possible values are: Unknown, Pending, Running, Succeeded, and Failed. | ||
// +kubebuilder:validation:Type=string | ||
Phase AgentPhase `json:"phase,omitempty"` | ||
|
||
// Conditions store a list of states that have been reached. | ||
// Each condition refers to the status of the Job | ||
// Possible conditions are: Scheduled, Started, Completed, and Failed | ||
Conditions []metav1.Condition `json:"conditions,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:subresource:status | ||
|
||
// AgentAction is the Schema for the agentactions API | ||
type AgentAction struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec AgentActionSpec `json:"spec,omitempty"` | ||
Status AgentActionStatus `json:"status,omitempty"` | ||
} | ||
|
||
func (a *AgentAction) GetConditions() *[]metav1.Condition { | ||
return &a.Status.Conditions | ||
} | ||
|
||
// GetRetryLabelValue returns a value that is safe to use | ||
// as a label value and represents the retry annotation used | ||
// to trigger reconciliation. | ||
func (a *AgentAction) GetRetryLabelValue() string { | ||
return getRetryLabelValue(a.Annotations) | ||
} | ||
|
||
// SetRetryAnnotation flags the resource to retry its last operation. | ||
func (a *AgentAction) SetRetryAnnotation(retry string) { | ||
if a.Annotations == nil { | ||
a.Annotations = make(map[string]string, 1) | ||
} | ||
a.Annotations[AnnotationRetry] = retry | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// AgentActionList contains a list of AgentAction | ||
type AgentActionList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []AgentAction `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&AgentAction{}, &AgentActionList{}) | ||
} |
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,13 @@ | ||
package v1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAgentAction_SetRetryAnnotation(t *testing.T) { | ||
action := AgentAction{} | ||
action.SetRetryAnnotation("retry-1") | ||
assert.Equal(t, "retry-1", action.Annotations[AnnotationRetry]) | ||
} |
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 |
---|---|---|
|
@@ -54,7 +54,7 @@ func (c AgentConfigSpec) GetPorterImage() string { | |
// We don't use a mutable tag like latest, or canary because it's a bad practice that we don't want to encourage. | ||
// As we test out the operator with new versions of Porter, keep this value up-to-date so that the default | ||
// version is guaranteed to work. | ||
version = "v1.0.0-alpha.8" | ||
version = "v1.0.0-alpha.12" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be set via a const in api/v1/const.go? |
||
} | ||
repo := c.PorterRepository | ||
if repo == "" { | ||
|
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,16 @@ | ||
package v1 | ||
|
||
const ( | ||
LabelJobType = Prefix + "jobType" | ||
JobTypeAgent = "porter-agent" | ||
JobTypeInstaller = "bundle-installer" | ||
LabelSecretType = Prefix + "secretType" | ||
SecretTypeConfig = "porter-config" | ||
SecretTypeWorkdir = "workdir" | ||
LabelManaged = Prefix + "managed" | ||
LabelResourceKind = Prefix + "resourceKind" | ||
LabelResourceName = Prefix + "resourceName" | ||
LabelResourceGeneration = Prefix + "resourceGeneration" | ||
LabelRetry = Prefix + "retry" | ||
FinalizerName = Prefix + "finalizer" | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that we can use the official release version now