Skip to content

Commit b00c51e

Browse files
authored
Support registration of multiple Porch repositories pointing to the same Git repository, and add webhook validation to detect and handle conflicts during repository creation (kptdev#335)
* Add support for multiple porch repos to connect to the same git repo - Create validation webhook for repositories.config.porch.kpt.dev - Update directory naming convention for git repo caching * Add ns separation for same repos regitered in different namespaces * Add repolocks for open and close * Add missing package path and remove duplication of packages when listing * Add git branch logic for conflicts and use apiserver client in webhooks * Add cachedir pooling and refactor git.go * Add Client.Reader for webhooks and modify logs in webhooks.go * Update Lock, e2e test and reject branch changes * Create commitopsbuilder and add unit tests * Use sync.Map to simplify mutex handling and remove client.Reader * Rebase and refactor e2e tests with new structure
1 parent dbae7e1 commit b00c51e

25 files changed

Lines changed: 2097 additions & 767 deletions

pkg/apiserver/apiserver.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func (c completedConfig) getRestConfig() (*rest.Config, error) {
139139
}
140140
}
141141

142-
func (c completedConfig) getCoreClient() (client.WithWatch, error) {
142+
func (c completedConfig) buildClient() (client.WithWatch, error) {
143143
restConfig, err := c.getRestConfig()
144144
if err != nil {
145145
return nil, err
@@ -153,26 +153,17 @@ func (c completedConfig) getCoreClient() (client.WithWatch, error) {
153153
if err := configapi.AddToScheme(scheme); err != nil {
154154
return nil, fmt.Errorf("error building scheme: %w", err)
155155
}
156-
157156
if err := porchapi.AddToScheme(scheme); err != nil {
158157
return nil, fmt.Errorf("error building scheme: %w", err)
159158
}
160-
161159
if err := corev1.AddToScheme(scheme); err != nil {
162160
return nil, fmt.Errorf("error building scheme: %w", err)
163161
}
164162
if err := internalapi.AddToScheme(scheme); err != nil {
165163
return nil, fmt.Errorf("error building scheme: %w", err)
166164
}
167165

168-
coreClient, err := client.NewWithWatch(restConfig, client.Options{
169-
Scheme: scheme,
170-
})
171-
if err != nil {
172-
return nil, fmt.Errorf("error building client for core apiserver: %w", err)
173-
}
174-
175-
return coreClient, nil
166+
return client.NewWithWatch(restConfig, client.Options{Scheme: scheme})
176167
}
177168

178169
func (c completedConfig) getCoreV1Client() (*corev1client.CoreV1Client, error) {
@@ -198,7 +189,7 @@ func (c completedConfig) New(ctx context.Context) (*PorchServer, error) {
198189
return nil, err
199190
}
200191

201-
coreClient, err := c.getCoreClient()
192+
coreClient, err := c.buildClient()
202193
if err != nil {
203194
return nil, fmt.Errorf("failed to build client for core apiserver: %w", err)
204195
}
@@ -305,7 +296,7 @@ func (s *PorchServer) Run(ctx context.Context) error {
305296
// but for now we keep backward compatiblity
306297
certStorageDir, found := os.LookupEnv("CERT_STORAGE_DIR")
307298
if found && strings.TrimSpace(certStorageDir) != "" {
308-
if err := setupWebhooks(ctx); err != nil {
299+
if err := setupWebhooks(ctx, s.coreClient); err != nil {
309300
klog.Errorf("%v\n", err)
310301
return err
311302
}

0 commit comments

Comments
 (0)