Skip to content
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

Remote Agent Part1: bootstrap #622

Open
wants to merge 5 commits into
base: remote-agent
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ go.work
*.log

docs-site/node_modules
docs-site/.hugo_build.lock
docs-site/.hugo_build.lock

remote-agent/bin
8 changes: 8 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ RUN mkdir /workspace
COPY ./packages /workspace/packages
COPY ./coa /workspace/coa
COPY ./api /workspace/api
COPY ./remote-agent /workspace/remote-agent

WORKDIR /workspace/remote-agent
RUN CGO_ENABLED=${CGO_ENABLED} GOOS=linux GOARCH=amd64 go build -o /remote-agent/remote-agent
RUN CGO_ENABLED=${CGO_ENABLED} GOOS=windows GOARCH=amd64 go build -o /remote-agent/remote-agent.exe

WORKDIR /workspace/api
# File permissions are not preserved when copying files in ADO.
RUN chmod +x pkg/apis/v1alpha1/providers/target/script/mock-*.sh
Expand Down Expand Up @@ -56,6 +62,8 @@ RUN \
ADD https://github.com/golang/go/raw/master/lib/time/zoneinfo.zip /zoneinfo.zip
ENV ZONEINFO=/zoneinfo.zip
COPY --from=build /dist /
RUN mkdir /remote-agent
COPY --from=build /remote-agent /v1alpha2/files
ADD ./api/symphony-api.json /
EXPOSE 8080
EXPOSE 8081
Expand Down
9 changes: 9 additions & 0 deletions api/pkg/apis/v1alpha1/managers/targets/targets-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/eclipse-symphony/symphony/coa/pkg/apis/v1alpha2/observability"
"github.com/eclipse-symphony/symphony/coa/pkg/apis/v1alpha2/providers"
"github.com/eclipse-symphony/symphony/coa/pkg/apis/v1alpha2/providers/registry"
"github.com/eclipse-symphony/symphony/coa/pkg/apis/v1alpha2/providers/secret"
"github.com/eclipse-symphony/symphony/coa/pkg/apis/v1alpha2/providers/states"
"github.com/eclipse-symphony/symphony/coa/pkg/apis/v1alpha2/utils"
"github.com/eclipse-symphony/symphony/coa/pkg/logger"
Expand All @@ -35,6 +36,7 @@ type TargetsManager struct {
RegistryProvider registry.IRegistryProvider
needValidate bool
TargetValidator validation.TargetValidator
SecretProvider secret.ISecretProvider
}

func (s *TargetsManager) Init(context *contexts.VendorContext, config managers.ManagerConfig, providers map[string]providers.IProvider) error {
Expand All @@ -54,6 +56,13 @@ func (s *TargetsManager) Init(context *contexts.VendorContext, config managers.M
// s.TargetValidator = validation.NewTargetValidator(s.targetInstanceLookup, s.targetUniqueNameLookup)
s.TargetValidator = validation.NewTargetValidator(nil, s.targetUniqueNameLookup)
}

for _, p := range providers {
if c, ok := p.(secret.ISecretProvider); ok {
s.SecretProvider = c
}
}

return nil
}

Expand Down
121 changes: 121 additions & 0 deletions api/pkg/apis/v1alpha1/model/message_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT license.
* SPDX-License-Identifier: MIT
*/

package model

import (
"time"
)

type JobPhase string

const (
PhaseGet JobPhase = "get"
PhaseApply JobPhase = "apply"
DeploymentPlanTopic = "deployment-plan"
DeploymentStepTopic = "deployment-step"
CollectStepResultTopic = "step-result"
)

type PlanResult struct {
PlanState PlanState `json:"planstate"`
EndTime time.Time `json:"endTime"`
Error string `json:"error,omitempty"`
}

type PlanEnvelope struct {
Plan DeploymentPlan `json:"plan"`
Deployment DeploymentSpec `json:"deployment"`
MergedState DeploymentState `json:"mergedState"`
PreviousDesiredState SolutionManagerDeploymentState `json:"previousDesiredState"`
CurrentState DeploymentState `json:"currentState"`
Remove bool `json:"remove"`
Namespace string `json:"namespace"`
PlanId string `json:"planId"`
Generation string `json:"generation"` // deployment version
Hash string `json:"hash"`
Phase JobPhase `json:"phase"`
}

// for step
type StepResult struct {
Step DeploymentStep `json:"step"`
TargetResultSpec TargetResultSpec `json:"targetResult"`
PlanId string `json:"planId"`
StepId int `json:"stepId"`
Timestamp time.Time `json:"timestamp"`
GetResult []ComponentSpec `json:"getResult"` // for get result
ApplyResult map[string]ComponentResultSpec `json:"components"` // for apply result
Error string `json:"string,omitempty"`
Target string `json:"Target"`
NameSpace string `json:"Namespace"`
}
type StepEnvelope struct {
Step DeploymentStep `json:"step"`
Remove bool `json:"remove"`
StepId int `json:"stepId"`
PlanState PlanState `json:"planState"`
}

type OperationBody struct {
StepId int `json:"stepId"`
PlanId string `json:"planId"`
Target string `json:"Target"`
Action JobPhase `json:"action"`
NameSpace string `json:"Namespace"`
Remove bool `json:"remove"`
MessageId string `json:"messageId"`
}

type StepState struct {
Index int `json:"Index"`
Target string `json:"Target"`
Role string `json:"Role"`
Components []ComponentStep `json:"Components"`
State string `json:"State"`
GetResult []ComponentSpec `json:"GetResult"`
Error string `json:"Error"`
}

type AgentRequest struct {
OperationID string `json:"operationID"`
Provider string `json:"provider"`
Action string `json:"action"`
}

type ProviderGetRequest struct {
AgentRequest
Deployment DeploymentSpec `json:"deployment"`
References []ComponentStep `json:"references"`
}

type ProviderPagingRequest struct {
RequestList []map[string]interface{} `json:"requestList"`
LastMessageID string `json:"lastMessageID"`
}
type ProviderApplyRequest struct {
AgentRequest
Deployment DeploymentSpec `json:"deployment"`
Step DeploymentStep `json:"step"`
IsDryRun bool `json:"isDryRun,omitempty"`
}

type ProviderGetValidationRuleRequest struct {
AgentRequest
}

type AsyncResult struct {
OperationID string `json:"operationID"`
Namespace string `json:"namespace"`
Error error `json:"error,omitempty"`
Body []byte `json:"body"`
}

type SymphonyEndpoint struct {
BaseUrl string `json:"baseUrl"`
RequestEndpoint string `json:"requestEndpoint,omitempty"`
ResponseEndpoint string `json:"responseEndpoint,omitempty"`
}
20 changes: 20 additions & 0 deletions api/pkg/apis/v1alpha1/model/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,23 @@ func (s *SummarySpec) UpdateTargetResult(target string, spec TargetResultSpec) {
func (summary *SummaryResult) IsDeploymentFinished() bool {
return summary.State == SummaryStateDone
}

type SolutionManagerDeploymentState struct {
Spec DeploymentSpec `json:"spec,omitempty"`
State DeploymentState `json:"state,omitempty"`
}
type PlanState struct {
PlanId string `json:"planId"`
Phase JobPhase
CompletedSteps int `json:"completedSteps"`
Status string `json:"status"`
MergedState DeploymentState `json:"mergedState"`
Deployment DeploymentSpec `json:"deployment"`
CurrentState DeploymentState `json:"currentState"`
PreviousDesiredState SolutionManagerDeploymentState `json:"previousDesiredState`
TargetResult map[string]int `json:"targetResult"`
Namespace string `json:"namespace"`
TotalSteps int `json:"totalSteps"`
StepStates []StepState `json:"stepStates"`
Steps []DeploymentStep `json:"steps"`
}
2 changes: 2 additions & 0 deletions api/pkg/apis/v1alpha1/providers/secret/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ func (s *K8sSecretProvider) Read(ctx context.Context, name string, field string,
defer observ_utils.CloseSpanWithError(span, &err)
defer observ_utils.EmitUserDiagnosticsLogs(ctx, &err)

jsonData, err := json.Marshal(localContext)
sLog.DebugfCtx(ctx, " P (K8s Secret): read secret %s field %s with context %s", name, field, string(jsonData))
namespace := utils.GetNamespaceFromContext(localContext)
secret, err := s.Clientset.CoreV1().Secrets(namespace).Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
Expand Down
Loading
Loading