-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PMK-3900: Adding pf9-profile-agent addon (#24)
- Loading branch information
1 parent
87f5cfb
commit 585a6eb
Showing
5 changed files
with
225 additions
and
0 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
69 changes: 69 additions & 0 deletions
69
addon_templates/pf9-profile-agent/1.0.0/pf9-profile-agent.yaml
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,69 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: pf9-profile-agent | ||
namespace: platform9-system | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: pf9-profile-agent | ||
rules: | ||
- apiGroups: ["*"] | ||
resources: ["*"] | ||
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"] | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: pf9-profile-agent | ||
subjects: | ||
- kind: ServiceAccount | ||
name: pf9-profile-agent | ||
namespace: platform9-system | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: pf9-profile-agent | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: pf9-addons | ||
name: pf9-profile-agent | ||
namespace: platform9-system | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: pf9-addons | ||
template: | ||
metadata: | ||
labels: | ||
app: pf9-addons | ||
spec: | ||
serviceAccountName: pf9-profile-agent | ||
hostNetwork: true | ||
containers: | ||
- name: pf9-profile-agent | ||
image: {{ .DockerRegistry }}/platform9/pf9-profile-agent:1.0.0 | ||
imagePullPolicy: IfNotPresent | ||
resources: | ||
limits: | ||
memory: "128Mi" | ||
cpu: "500m" | ||
env: | ||
- name: CLUSTER_ID | ||
value: {{ .ClusterId }} | ||
- name: PROJECT_ID | ||
value: {{ .ProjectId }} | ||
- name: DEBUG | ||
value: "true" | ||
tolerations: | ||
- effect: NoSchedule | ||
key: node-role.kubernetes.io/master | ||
operator: Equal | ||
value: "true" | ||
nodeSelector: | ||
node-role.kubernetes.io/master: "" |
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,142 @@ | ||
package addons | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/platform9/pf9-addon-operator/pkg/util" | ||
log "github.com/sirupsen/logrus" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
const ( | ||
profileAgentNs = "platform9-system" | ||
profileAgentDeployment = "pf9-profile-agent" | ||
profileAgentDir = "pf9-profile-agent" | ||
) | ||
|
||
// ProfileAgentClient represents the pf9-profile-agent addon | ||
type ProfileAgentClient struct { | ||
client client.Client | ||
overrideParams map[string]interface{} | ||
version string | ||
} | ||
|
||
func newProfileAgent(c client.Client, version string, params map[string]interface{}) *ProfileAgentClient { | ||
|
||
cl := &ProfileAgentClient{ | ||
client: c, | ||
overrideParams: params, | ||
version: version, | ||
} | ||
|
||
return cl | ||
} | ||
|
||
//overrideRegistry checks if we need to override container registry values | ||
func (c *ProfileAgentClient) overrideRegistry() { | ||
overrideRegistry := util.GetRegistry(envVarDockerRegistry, "docker.io") | ||
c.overrideParams[templateDockerRegistry] = overrideRegistry | ||
|
||
log.Infof("Using container registry: %s", c.overrideParams[templateDockerRegistry]) | ||
} | ||
|
||
//ValidateParams validates params of an addon | ||
func (c *ProfileAgentClient) ValidateParams() (bool, error) { | ||
|
||
return true, nil | ||
} | ||
|
||
//Health checks health of the pf9-profile-agent instance | ||
func (c *ProfileAgentClient) Health() (bool, error) { | ||
deploy, err := util.GetDeployment(profileAgentNs, profileAgentDeployment, c.client) | ||
if err != nil { | ||
log.Errorf("Failed to get deployment: %s", err) | ||
return false, err | ||
} | ||
|
||
if deploy == nil { | ||
return false, nil | ||
} | ||
|
||
if deploy.Status.ReadyReplicas > 0 { | ||
return true, nil | ||
} | ||
|
||
return false, nil | ||
} | ||
|
||
//Upgrade upgrades an pf9-profile-agent instance | ||
func (c *ProfileAgentClient) Upgrade() error { | ||
return c.Install() | ||
} | ||
|
||
//Install installs an pf9-profile-agent instance | ||
func (c *ProfileAgentClient) Install() error { | ||
|
||
inputPath, outputPath, err := util.EnsureDirStructure(profileAgentDir, c.version) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
inputFilePath := filepath.Join(inputPath, "pf9-profile-agent.yaml") | ||
outputFilePath := filepath.Join(outputPath, "pf9-profile-agent.yaml") | ||
|
||
c.overrideRegistry() | ||
|
||
// Fetch and add clusterID/projectID to the overrideParams | ||
clusterID := os.Getenv(util.ClusterIDEnvVar) | ||
projectID := os.Getenv(util.ProjectIDEnvVar) | ||
c.overrideParams["ClusterId"] = clusterID | ||
c.overrideParams["ProjectId"] = projectID | ||
|
||
labels := []util.Labels{} | ||
|
||
err = util.CreateNsIfNeeded(profileAgentNs, labels, c.client) | ||
if err != nil { | ||
log.Errorf("Failed to create ns: %s %s", profileAgentNs, err) | ||
return err | ||
} | ||
|
||
err = util.WriteConfigToTemplate(inputFilePath, outputFilePath, "pf9-profile-agent.yaml", c.overrideParams) | ||
if err != nil { | ||
log.Errorf("Failed to write output file: %s", err) | ||
return err | ||
} | ||
|
||
err = util.ApplyYaml(outputFilePath, c.client) | ||
if err != nil { | ||
log.Errorf("Failed to apply yaml file: %s", err) | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
//Uninstall removes an dashboard instance | ||
func (c *ProfileAgentClient) Uninstall() error { | ||
|
||
inputPath, outputPath, err := util.EnsureDirStructure(profileAgentDir, c.version) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
inputFilePath := filepath.Join(inputPath, "pf9-profile-agent.yaml") | ||
outputFilePath := filepath.Join(outputPath, "pf9-profile-agent.yaml") | ||
|
||
c.overrideRegistry() | ||
|
||
err = util.WriteConfigToTemplate(inputFilePath, outputFilePath, "pf9-profile-agent.yaml", c.overrideParams) | ||
if err != nil { | ||
log.Errorf("Failed to write output file: %s", err) | ||
return err | ||
} | ||
|
||
err = util.DeleteYaml(outputFilePath, c.client) | ||
if err != nil { | ||
log.Errorf("Failed to delete yaml file: %s", err) | ||
return err | ||
} | ||
|
||
return nil | ||
} |
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,8 @@ | ||
apiVersion: agent.pf9.io/v1 | ||
kind: Addon | ||
metadata: | ||
name: pf9-profile-agent | ||
spec: | ||
version: 1.0.0 | ||
type: "pf9-profile-agent" | ||
watch: true |