-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I've split the installation controller in two, adding a new controller just to manage running the porter agent. The installation controller now only is reponsible for creating an AgentAction resource. This triggers the AgentAction controller to make a porter agent job to execute the command from the AgentAction. It's a bit of an extra layer of indirection but it will simplify additional controllers since they don't need to manage the porter agent job. It also enables users to request that the porter agent is run and can specify arbitrary commands, such as invoke. Signed-off-by: Carolyn Van Slyck <[email protected]>
- Loading branch information
Showing
48 changed files
with
4,551 additions
and
1,491 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 |
---|---|---|
|
@@ -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
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 | ||
// 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
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.