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

Implement git repository controller #82

Merged
merged 4 commits into from
Nov 24, 2023

Conversation

nabuskey
Copy link
Collaborator

This implements the git repository types and controller.

Syncs the contents of a local directory to an in-cluster gitea repository for ArgoCD to pick up.

We need #39 merged first.

closes #59, closes #60

@nabuskey nabuskey marked this pull request as draft November 14, 2023 22:53
@nabuskey nabuskey changed the title Feature/git controller Implement git repository controller Nov 14, 2023
@nabuskey nabuskey force-pushed the feature/git-controller branch 2 times, most recently from cd01ed4 to 6538ae2 Compare November 16, 2023 23:26
@nabuskey nabuskey marked this pull request as ready for review November 16, 2023 23:26

const (
DefaultBranchName = "main"
// DefaultGiteaUsername and DefaultGiteaPassword taken from gitea helm chart. https://gitea.com/gitea/helm-chart#gitea
Copy link
Collaborator Author

@nabuskey nabuskey Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a way to get these values dynamically. If the gitea object can expose that information, we can do so. Otherwise we will have to rely on a secret naming convention. e.g. we will always look for a secret named abc in namespace abc.

Copy link
Contributor

@nimakaviani nimakaviani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks neat, thanks. left a few comments.

Also, looks like the bit that actually hooks things up and runs this in RunControllers is not here in this commit. intentional?

pkg/controllers/gitrepository/controller.go Outdated Show resolved Hide resolved
pkg/controllers/gitrepository/controller.go Outdated Show resolved Hide resolved
pkg/controllers/gitrepository/controller.go Outdated Show resolved Hide resolved
api/v1alpha1/gitrepository_types.go Outdated Show resolved Hide resolved
pkg/controllers/gitrepository/controller.go Show resolved Hide resolved
@nimakaviani
Copy link
Contributor

also looks like you've got some conflicts to resolve

@nabuskey nabuskey force-pushed the feature/git-controller branch 2 times, most recently from dd48340 to cb6156f Compare November 21, 2023 01:34
@nabuskey
Copy link
Collaborator Author

nabuskey commented Nov 21, 2023

This PR's become a bit too large for my liking but it implements the entire workflow with Gitea.

All emebdded manifests are pushed to gitea server under the admin user organization. We may want to make this configurable in the future.

image

Once they are pushed, argo applications are created. They reference the repos created above. From here, ArgoCD takes care of the rest. The Git repository contents are reconciled only once for embedded applications. If users wants to reconfigure things, they can do so in the Gitea UI.

image

Once this PR merges, I just need to rebase and build should pass.

push manifests to gitea

Signed-off-by: Manabu Mccloskey <[email protected]>
@nabuskey nabuskey force-pushed the feature/git-controller branch from cb6156f to d27a5ae Compare November 21, 2023 19:18
Signed-off-by: Manabu Mccloskey <[email protected]>
@nabuskey nabuskey force-pushed the feature/git-controller branch from d27a5ae to 6dd8cda Compare November 21, 2023 19:22
Signed-off-by: Manabu Mccloskey <[email protected]>
Copy link
Contributor

@nimakaviani nimakaviani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few minor updates. otherwise looks good.

One higher level question, for the backstage embeded app, shall we use the helm chart with its image set to our CNOE backstage image and let Argo CD handle it, rather than having the raw resources?

api/v1alpha1/localbuild_types.go Outdated Show resolved Hide resolved
pkg/controllers/gitrepository/controller.go Outdated Show resolved Hide resolved
pkg/controllers/gitrepository/resources/file1 Outdated Show resolved Hide resolved
Comment on lines -281 to +282
log := log.FromContext(ctx)
logger := log.FromContext(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we have called the variable log in other places. would be good to make this consistent across the board and btw i like logger better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem with using log is that it collides with package import like this

"sigs.k8s.io/controller-runtime/pkg/log"

I agree that we should use logger instead of log across the project. I'll file an issue.

giteaAdminSecret = "gitea-admin-secret"
// this is the URL accessible outside cluster. resolves to localhost
giteaIngressURL = "http://gitea.cnoe.localtest.me:8880"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8443 or 8880 for the port number?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be 8880. We should consider using TLS in the future, but it's all http for gitea as of now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be 8880. We should consider using TLS in the future, but it's all http for gitea as of now.

I don t think that we should append additional ports to the URL as we do now:

  • https://argocd.<host_IP>.<DOMAIN>:8443,
  • https://gitea.<host_IP>.<DOMAIN>:8880,
  • https://backstage.<host_IP>.<DOMAIN>:8443,
  • etc

Why: ?

  • Adding more and more new ports will make the work of the users not really cool and easy as they will have to remember the ports to be used for each component
  • Only default HTTP(S) ports are needed and will be recognized by the browser: 80, 443 automatically.
  • As the ingress controller which is acting as a reverse proxy using nginx is able to forward from URL: https://backend>.<host_ip>.<domain> the packets to the target backends: argocd, backstage, vault, gitea, etc then adding new ports make the job to configure ingress + kind part of the idpbuilder hardder instead of having Ingress YAML files

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree from the user friendliness standpoint. The reason we are not using default http and https ports is that allocation of lower number port (< 1024) requires higher privileges that some organizations do not allow end users to have. I would like to use default ports but I would rather have the assurance that port allocation will work for all users. Maybe we can make it configurable in the future.

// Type is the source type.
// +kubebuilder:validation:Enum:=local;embedded
// +kubebuilder:default:=embedded
Type string `json:"type"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you describe what is the purpose of the type and what will happen if we select one the values: local, embedded, etc ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local indicates the gitea repository contents will come from a local directory. E.g. /home/ubuntu/myrepo

Embedded indicates the repository contents will come from what is embedded in the go binary.

}

type GitRepositorySource struct {
// +kubebuilder:validation:Enum:=argocd;backstage;crossplane;gitea;nginx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crossplane should be removed from the enum and we should keep what currently we support or point to a link = doc page enumerating them

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will probably have to keep it since the reference implementation uses it. For now, I am keeping it because the purpose of this PR is to move the git functionality over from embedded git server to gitea.

ExternalGitRepositoryUrl string `json:"externalGitRepositoryUrl"`
// GitRepositoryUrl is the url for the in-cluster repository accessible within the cluster.
// +kubebuilder:validation:Optional
GitRepositoryUrl string `json:"gitRepositoryUrl"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you name it InternalGitRepositoryUrl as it is used for internal purposes ? If we use gitea which is accessible by the users, does that makes sense that we keep ext vs internal repos ?

Copy link
Collaborator Author

@nabuskey nabuskey Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea I will rename the field.

We need to distinct the internal and external git repo URLs (gitea.cnoe.localtest.me) because the domain name will always resolve to 127.0.0.1. Therefore this URL is not usable by ArgoCD to fetch manifests from the gitea server.

Signed-off-by: Manabu Mccloskey <[email protected]>
@nabuskey nabuskey force-pushed the feature/git-controller branch from d7ae0fe to 9d00824 Compare November 24, 2023 17:36
@nabuskey nabuskey merged commit ca8f132 into cnoe-io:main Nov 24, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Git Repository reconciler API type for Git repository
5 participants