Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

Commit

Permalink
fix(sprvsr): Properly enable deployments for select repos
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Jan 8, 2021
1 parent 796d22e commit f7bd12f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 21 deletions.
4 changes: 4 additions & 0 deletions drghs-worker/maintner-sprvsr/main.go
Expand Up @@ -418,4 +418,8 @@ func bucketName(t repos.TrackedRepository) string {
return path.Join(*mutationBucket)
}

func shouldDeploy(ta repos.TrackedRepository) bool {
return ta.IsTrackingIssues
}

func int32Ptr(i int32) *int32 { return &i }
14 changes: 7 additions & 7 deletions leif/repos_disk.go
Expand Up @@ -63,9 +63,9 @@ func (r *diskRepoList) GetTrackedRepos() []repos.TrackedRepository {
}

type diskRepo struct {
Repo string `json:"repo"`
IsTrackingIssues bool `json:"is_tracking_issues"`
IsTrackingSnippets bool `json:"is_tracking_snippets"`
Repo string `json:"repo"`
IsTrackingIssues bool `json:"is_tracking_issues"`
IsTrackingSamples bool `json:"is_tracking_samples"`
}

func (r *diskRepoList) getRepos() ([]repos.TrackedRepository, error) {
Expand All @@ -92,10 +92,10 @@ func (r *diskRepoList) getRepos() ([]repos.TrackedRepository, error) {
}

convertedRepos[i] = repos.TrackedRepository{
Owner: repoPath[0],
Name: repoPath[1],
IsTrackingIssues: repo.IsTrackingIssues,
IsTrackingSnippets: repo.IsTrackingSnippets,
Owner: repoPath[0],
Name: repoPath[1],
IsTrackingIssues: repo.IsTrackingIssues,
IsTrackingSamples: repo.IsTrackingSamples,
}
}

Expand Down
10 changes: 5 additions & 5 deletions repos/repos.go
Expand Up @@ -30,11 +30,11 @@ type RepoList interface {

// TrackedRepository represents a repository tracked by Maintner or Samplr
type TrackedRepository struct {
Owner string `json:"owner"`
Name string `json:"name"`
DefaultBranch string `json:"defaultBranch"`
IsTrackingIssues bool `json:"isTrackingIssues"`
IsTrackingSnippets bool `json:"isTrackingSnippets"`
Owner string `json:"owner"`
Name string `json:"name"`
DefaultBranch string `json:"defaultBranch"`
IsTrackingIssues bool `json:"isTrackingIssues"`
IsTrackingSamples bool `json:"isTrackingSamples"`
}

// RepoSha Creates a Sum224 of the TrackedRepository's name
Expand Down
18 changes: 9 additions & 9 deletions repos/repos_bucket.go
Expand Up @@ -65,10 +65,10 @@ func (r *bucketRepoList) GetTrackedRepos() []TrackedRepository {
}

type bucketRepo struct {
Repo string `json:"repo"`
DefaultBranch string `json:"default_branch"`
IsTrackingIssues bool `json:"is_tracking_issues"`
IsTrackingSnippets bool `json:"is_tracking_snippets"`
Repo string `json:"repo"`
DefaultBranch string `json:"default_branch"`
IsTrackingIssues bool `json:"is_tracking_issues"`
IsTrackingSamples bool `json:"is_tracking_samples"`
}

func (r *bucketRepoList) getRepos(ctx context.Context) ([]TrackedRepository, error) {
Expand Down Expand Up @@ -108,11 +108,11 @@ func (r *bucketRepoList) getRepos(ctx context.Context) ([]TrackedRepository, err
}

tr := TrackedRepository{
Owner: parts[0],
Name: parts[1],
IsTrackingIssues: re.IsTrackingIssues,
IsTrackingSnippets: re.IsTrackingSnippets,
DefaultBranch: re.DefaultBranch,
Owner: parts[0],
Name: parts[1],
IsTrackingIssues: re.IsTrackingIssues,
IsTrackingSamples: re.IsTrackingSamples,
DefaultBranch: re.DefaultBranch,
}
reps[i] = tr
}
Expand Down
5 changes: 5 additions & 0 deletions samplr/samplr-sprvsr/main.go
Expand Up @@ -165,6 +165,7 @@ func main() {
ServiceBuilder: buildService,
DeploymentBuilder: bd,
PreDeploy: preDeploy,
ShouldDeploy: shouldDeploy,
}

super, err := sprvsr.NewK8sSupervisor(log, cs, kcfg, repoList, "samplr")
Expand Down Expand Up @@ -298,4 +299,8 @@ func preDeploy(ta repos.TrackedRepository) error {
return nil
}

func shouldDeploy(ta repos.TrackedRepository) bool {
return ta.IsTrackingSamples
}

func int32Ptr(i int32) *int32 { return &i }
11 changes: 11 additions & 0 deletions sprvsr/k8s_supervisor.go
Expand Up @@ -52,6 +52,7 @@ type k8supervisor struct {
deploymentNamer DeploymentNamer
serviceBuilder ServiceBuilder
deploymentPrep DeploymentPrep
deploymentCheck DeploymentCheck
deploymentBuilder DeploymentBuilder

// The list of repositories to track
Expand All @@ -77,6 +78,10 @@ type ServiceBuilder func(repos.TrackedRepository) (*apiv1.Service, error)
// used to provision additional resources before the Deployment is applied
type DeploymentPrep func(repos.TrackedRepository) error

// DeploymentCheck is called to decide whether a deployment should be
// created for a given TrackedRepository.
type DeploymentCheck func(repos.TrackedRepository) bool

// K8sConfiguration is a struct to describe the set of operations
// a K8SSupervisor needs to manage a cluster
type K8sConfiguration struct {
Expand All @@ -85,6 +90,7 @@ type K8sConfiguration struct {
ServiceBuilder ServiceBuilder
DeploymentBuilder DeploymentBuilder
PreDeploy DeploymentPrep
ShouldDeploy DeploymentCheck
}

// NewK8sSupervisor creates a new supervisor backed by Kubernetes
Expand All @@ -108,6 +114,7 @@ func newK8sSupervisor(log *logrus.Logger, clientset kubernetes.Interface, kconfi
serviceBuilder: kconfig.ServiceBuilder,
deploymentBuilder: kconfig.DeploymentBuilder,
deploymentPrep: kconfig.PreDeploy,
deploymentCheck: kconfig.ShouldDeploy,
repoList: rl,
labelgenkey: lblkey,
}, nil
Expand Down Expand Up @@ -171,6 +178,10 @@ func (s *k8supervisor) updateCorpusRepoList(ctx context.Context, handle func(err
handle(err)
return
}

if !s.deploymentCheck(tr) {
continue
}
imgs := make([]string, 0)
for _, i := range d.Spec.Template.Spec.Containers {
imgs = append(imgs, i.Image)
Expand Down

0 comments on commit f7bd12f

Please sign in to comment.