-
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.
* Include manager image in bundle Add an image reference to the manager image (which has the controllers) to the bundle and then reference it when installing the operator. Signed-off-by: Carolyn Van Slyck <[email protected]> * Add AgentAction controller 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]> * Use a constant for the default porter agent version Also update the default version to alpha.13 which is the most recent release. Signed-off-by: Carolyn Van Slyck <[email protected]> * Sync go.mod Signed-off-by: Carolyn Van Slyck <[email protected]> * Bump schemaversion used in test param/creds Signed-off-by: Carolyn Van Slyck <[email protected]> * Review feedback Signed-off-by: Carolyn Van Slyck <[email protected]>
- Loading branch information
Showing
55 changed files
with
4,813 additions
and
1,525 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.13 | ||
- 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 statuses 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,92 @@ | ||
package v1 | ||
|
||
const ( | ||
// DefaultPorterAgentRepository is the default image repository of the Porter | ||
// Agent to use when it is not configured in the operator. | ||
DefaultPorterAgentRepository = "ghcr.io/getporter/porter-agent" | ||
|
||
// DefaultPorterAgentVersion is the default version of the Porter Agent to | ||
// use when it is not configured in the operator. | ||
// | ||
// 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. | ||
DefaultPorterAgentVersion = "v1.0.0-alpha.13" | ||
|
||
// LabelJobType is a label applied to jobs created by the operator. It | ||
// indicates the purpose of the job. | ||
LabelJobType = Prefix + "jobType" | ||
|
||
// JobTypeAgent is the value of job type label applied to the Porter Agent. | ||
JobTypeAgent = "porter-agent" | ||
|
||
// JobTypeInstaller is the value of the job type label applied to the job | ||
// that runs the bundle. | ||
JobTypeInstaller = "bundle-installer" | ||
|
||
// LabelSecretType is a label applied to secrets created by the operator. It | ||
// indicates the purpose of the secret. | ||
LabelSecretType = Prefix + "secretType" | ||
|
||
// SecretTypeConfig is the value of the secret type label applied to the | ||
// secret that contains files to copy into the porter home directory. | ||
SecretTypeConfig = "porter-config" | ||
|
||
// SecretTypeWorkdir is the value of the secret type label applied to the | ||
// secret that contains files to copy into the working directory of the | ||
// Porter Agent. | ||
SecretTypeWorkdir = "workdir" | ||
|
||
// LabelManaged is a label applied to resources created by the Porter | ||
// Operator. | ||
LabelManaged = Prefix + "managed" | ||
|
||
// LabelResourceKind is a label applied to resources created by the Porter | ||
// Operator, representing the kind of owning resource. It is used to help the | ||
// operator determine if a resource has already been created. | ||
LabelResourceKind = Prefix + "resourceKind" | ||
|
||
// LabelResourceName is a label applied to the resources created by the | ||
// Porter Operator, representing the name of the owning resource. It is used | ||
// to help the operator determine if a resource has | ||
// already been created. | ||
LabelResourceName = Prefix + "resourceName" | ||
|
||
// LabelResourceGeneration is a label applied to the resources created by the | ||
// Porter Operator, representing the generation of the owning resource. It is | ||
// used to help the operator determine if a resource has | ||
// already been created. | ||
LabelResourceGeneration = Prefix + "resourceGeneration" | ||
|
||
// LabelRetry is a label applied to the resources created by the | ||
// Porter Operator, representing the retry attempt identifier. | ||
LabelRetry = Prefix + "retry" | ||
|
||
// FinalizerName is the name of the finalizer applied to Porter Operator | ||
// resources that should be reconciled by the operator before allowing it to | ||
// be deleted. | ||
FinalizerName = Prefix + "finalizer" | ||
|
||
// VolumePorterSharedName is the name of the volume shared between the porter | ||
// agent and the invocation image. | ||
VolumePorterSharedName = "porter-shared" | ||
|
||
// VolumePorterSharedPath is the mount path of the volume shared between the | ||
// porter agent and the invocation image. | ||
VolumePorterSharedPath = "/porter-shared" | ||
|
||
// VolumePorterConfigName is the name of the volume that contains Porter's config | ||
// file. | ||
VolumePorterConfigName = "porter-config" | ||
|
||
// VolumePorterConfigPath is the mount path of the volume containing Porter's | ||
// config file. | ||
VolumePorterConfigPath = "/porter-config" | ||
|
||
// VolumePorterWorkDirName is the name of the volume that is used as the Porter's | ||
// working directory. | ||
VolumePorterWorkDirName = "porter-workdir" | ||
|
||
// VolumePorterWorkDirPath is the mount path of the volume that is used as the | ||
// Porter's working directory. | ||
VolumePorterWorkDirPath = "/porter-workdir" | ||
) |
Oops, something went wrong.